X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Flogger.pl;h=3ad021abcbd4953a473ab38051d46151c5d876ef;hb=f06ee2cec2996f92167474845aee2f5112588288;hp=fd3d6a7d02f0582234dfdfead1a544099db11469;hpb=dd3a610c735093c82495a37a26a6353fd776dc43;p=infobot.git diff --git a/src/logger.pl b/src/logger.pl index fd3d6a7..3ad021a 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,10 +112,16 @@ 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 ); + my $logDir = $file{log} . sprintf('%04d', $year + 1900); + unless(-d $logDir) { + &status("openLog: making $logDir."); + mkdir $logDir, 0755 or &status("Cannot mkdir $logDir");; + } + $logDate = sprintf('%04d/%02d%02d', $year + 1900, $month + 1, $day); $file{log} .= $logDate; } + if ( open( LOG, ">>$file{log}" ) ) { binmode( LOG, ':encoding(UTF-8)' ); &status("Opened logfile $file{log}."); @@ -135,33 +143,33 @@ sub closeLog { } ##### -# Usage: &compress($file); -sub compress { +# Usage: &processLog($file); +sub processLog { my ($file) = @_; - my @compress = ( '/usr/bin/bzip2', '/bin/bzip2', '/bin/gzip' ); + my @processLog = ( 'scripts/processlog', '/usr/bin/bzip2', '/bin/bzip2', '/bin/gzip' ); my $okay = 0; if ( !-f $file ) { - &WARN("compress: file ($file) does not exist."); + &WARN("processLog: file ($file) does not exist."); return 0; } if ( -f "$file.gz" or -f "$file.bz2" ) { - &WARN('compress: file.(gz|bz2) already exists.'); + &WARN('processLog: file.(gz|bz2) already exists.'); return 0; } - foreach (@compress) { + foreach (@processLog) { next unless ( -x $_ ); - &status("Compressing '$file' with $_."); + &status("Processing log '$file' with $_."); system("$_ $file &"); $okay++; last; } if ( !$okay ) { - &ERROR('no compress program found.'); + &ERROR('no processLog program found.'); return 0; } @@ -400,10 +408,10 @@ sub status { my ( $day, $month, $year ) = ( gmtime $time )[ 3, 4, 5 ]; my $newlogDate = - sprintf( '%04d%02d%02d', $year + 1900, $month + 1, $day ); - if ( defined $logDate and $newlogDate != $logDate ) { + sprintf( '%04d/%02d%02d', $year + 1900, $month + 1, $day ); + if ( defined $logDate and $newlogDate ne $logDate ) { &closeLog(); - &compress( $file{log} ); + &processLog( $file{log} ); &openLog(); } }