]> git.donarmstrong.com Git - infobot.git/blobdiff - src/logger.pl
dunno
[infobot.git] / src / logger.pl
index 75ebebc448075e77d788d6786aecf94fef1c3f4e..6220dcd623b2f0b1c57ab384f9789c50081e58e4 100644 (file)
@@ -112,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}.");
@@ -137,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;
     }
 
@@ -172,12 +178,16 @@ sub compress {
 
 sub DEBUG {
     return unless ( &IsParam('DEBUG') );
+    my (undef,undef,$line,$subroutine,undef) = caller(1);
 
-    &status("${b_green}!DEBUG!$ob $_[0]");
+    &status("${b_green}!DEBUG!$ob ".$subroutine.'['.$line."] $_[0]");
 }
 
 sub ERROR {
-    &status("${b_red}!ERROR!$ob $_[0]");
+    return unless ( &IsParam('DEBUG') );
+    my (undef,undef,$line,$subroutine,undef) = caller(1);
+
+    &status("${b_red}!ERROR!$ob ".$subroutine.'['.$line."] $_[0]");
 }
 
 sub WARN {
@@ -185,15 +195,21 @@ sub WARN {
 
     return if ( $_[0] =~ /^PERL: Subroutine \S+ redefined at/ );
 
-    &status("${b_yellow}!WARN!$ob $_[0]");
+    my ($package,$filename,$line,$subroutine,undef) = caller(1);
+
+    &status("${b_yellow}!WARN!$ob ".$subroutine.'['.$line."] $_[0]");
 }
 
 sub FIXME {
-    &status("${b_cyan}!FIXME!$ob $_[0]");
+    my ($package,$filename,$line,$subroutine,undef) = caller(1);
+
+    &status("${b_cyan}!FIXME!$ob ".$subroutine.'['.$line."] $_[0]");
 }
 
 sub TODO {
-    &status("${b_cyan}!TODO!$ob $_[0]");
+    my ($package,$filename,$line,$subroutine,undef) = caller(1);
+
+    &status("${b_cyan}!TODO!$ob ".$subroutine.'['.$line."] $_[0]");
 }
 
 sub VERB {
@@ -402,10 +418,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();
         }
     }