]> git.donarmstrong.com Git - infobot.git/commitdiff
DAILY logs in year/ dir. allow for external scripts/processlog
authortimriker <timriker@c11ca15a-4712-0410-83d8-924469b57eb5>
Wed, 28 Dec 2011 22:24:59 +0000 (22:24 +0000)
committertimriker <timriker@c11ca15a-4712-0410-83d8-924469b57eb5>
Wed, 28 Dec 2011 22:24:59 +0000 (22:24 +0000)
git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk@1916 c11ca15a-4712-0410-83d8-924469b57eb5

src/logger.pl

index 75ebebc448075e77d788d6786aecf94fef1c3f4e..36400b3c0bcf24c70f8754779afc42c5208a405e 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 );
+        $logDate = sprintf('%04d/%02d%02d', $year + 1900, $month + 1, $day);
         $file{log} .= $logDate;
+       my $logDir = $file{log} . sprintf('%04d', $year + 1900);
+        unless(-d $logDir) {
+            &status("openLog: making $logDir.");
+            mkdir $logDir, 0755 or &status("Cannot mkdir $logDir");;
+        }
     }
 
+
     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;
     }
 
@@ -402,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 );
+          sprintf( '%04d/%02d%02d', $year + 1900, $month + 1, $day );
         if ( defined $logDate and $newlogDate != $logDate ) {
             &closeLog();
-            &compress( $file{log} );
+            &processLog( $file{log} );
             &openLog();
         }
     }