X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Flogger.pl;h=75ebebc448075e77d788d6786aecf94fef1c3f4e;hb=3536c5564f248374a76fa5eda24f4b9c5b2c54c1;hp=40a30ecbbb108c2292c9f4f4ef92e8f2ecde468b;hpb=40f6dad8bfd5a8a707a69cb31ba62cc6d26139c1;p=infobot.git diff --git a/src/logger.pl b/src/logger.pl index 40a30ec..75ebebc 100644 --- a/src/logger.pl +++ b/src/logger.pl @@ -7,6 +7,7 @@ # use strict; +use utf8; use vars qw($statcount $bot_pid $forkedtime $statcountfix $addressed); use vars qw($logDate $logold $logcount $logtime $logrepeat $running); @@ -91,6 +92,7 @@ sub cl { # logging support. sub openLog { + binmode( STDOUT, ':encoding(UTF-8)' ); return unless ( &IsParam('logfile') ); $file{log} = $param{'logfile'}; @@ -110,12 +112,12 @@ sub openLog { if ( &IsParam('logType') and $param{'logType'} =~ /DAILY/i ) { my ( $day, $month, $year ) = ( gmtime time() )[ 3, 4, 5 ]; - $logDate = sprintf( "%04d%02d%02d", $year + 1900, $month + 1, $day ); + $logDate = sprintf( '%04d%02d%02d', $year + 1900, $month + 1, $day ); $file{log} .= $logDate; } if ( open( LOG, ">>$file{log}" ) ) { - binmode( LOG, ":encoding(UTF-8)" ); + binmode( LOG, ':encoding(UTF-8)' ); &status("Opened logfile $file{log}."); LOG->autoflush(1); } @@ -147,7 +149,7 @@ sub compress { } if ( -f "$file.gz" or -f "$file.bz2" ) { - &WARN("compress: file.(gz|bz2) already exists."); + &WARN('compress: file.(gz|bz2) already exists.'); return 0; } @@ -161,7 +163,7 @@ sub compress { } if ( !$okay ) { - &ERROR("no compress program found."); + &ERROR('no compress program found.'); return 0; } @@ -243,7 +245,7 @@ sub status { # Something is using this w/ NULL. if ( !defined $input or $input =~ /^\s*$/ ) { - $input = "ERROR: Blank status call? HELP HELP HELP"; + $input = 'ERROR: Blank status call? HELP HELP HELP'; } for ($input) { @@ -279,7 +281,7 @@ sub status { } else { sleep 1; - &status("LOG: Throttling."); + &status('LOG: Throttling.'); $reset++; } } @@ -297,7 +299,7 @@ sub status { $status = "!$statcount! " . $input; if ( $statcount > 1000 ) { print LOG "ERROR: FORKED PROCESS RAN AWAY; KILLING.\n"; - print LOG "VERB: " . ( &Time2String( $time - $forkedtime ) ) . "\n"; + print LOG 'VERB: ' . ( &Time2String( $time - $forkedtime ) ) . "\n"; exit 0; } } @@ -312,10 +314,10 @@ sub status { if ( &IsParam('VERBOSITY') ) { if ($statcountfix) { - printf $_red. "!%6d!" . $ob . " ", $statcount; + printf $_red. '!%6d!' . $ob . ' ', $statcount; } else { - printf $_green. "[%6d]" . $ob . " ", $statcount; + printf $_green. '[%6d]' . $ob . ' ', $statcount; } # three uberstabs to Derek Moeller. I don't remember why but he @@ -396,11 +398,11 @@ sub status { my $date; if ( &IsParam('logType') and $param{'logType'} =~ /DAILY/i ) { - $date = sprintf( "%02d:%02d.%02d", ( gmtime $time )[ 2, 1, 0 ] ); + $date = sprintf( '%02d:%02d.%02d', ( gmtime $time )[ 2, 1, 0 ] ); my ( $day, $month, $year ) = ( gmtime $time )[ 3, 4, 5 ]; my $newlogDate = - sprintf( "%04d%02d%02d", $year + 1900, $month + 1, $day ); + sprintf( '%04d%02d%02d', $year + 1900, $month + 1, $day ); if ( defined $logDate and $newlogDate != $logDate ) { &closeLog(); &compress( $file{log} ); @@ -425,11 +427,11 @@ sub debug_perl { &status("WARN: cannot open $file: $!"); return; } - binmode( IN, ":encoding(UTF-8)" ); + binmode( IN, ':encoding(UTF-8)' ); # TODO: better filename. - open( OUT, ">>debug.log" ); - binmode( OUT, ":encoding(UTF-8)" ); + open( OUT, '>>debug.log' ); + binmode( OUT, ':encoding(UTF-8)' ); print OUT "DEBUG: $str\n"; # note: cannot call external functions because SIG{} does not allow us to. @@ -465,7 +467,7 @@ sub openSQLDebug { delete $param{'SQLDebug'}; return 0; } - binmode( SQLDEBUG, ":encoding(UTF-8)" ); + binmode( SQLDEBUG, ':encoding(UTF-8)' ); &status("Opened SQL Debug file: $param{'SQLDebug'}"); return 1;