]> git.donarmstrong.com Git - infobot.git/blobdiff - src/logger.pl
- patch from Morten Brix Pedersen:
[infobot.git] / src / logger.pl
index ad4efa53a4dd9979548eb96272c387a1af20eb8c..252f72b77278ef7bc37d2882c7db71e02ae8dba8 100644 (file)
@@ -9,9 +9,9 @@
 use strict;
 
 use vars qw($statcount $bot_pid $forkedtime $statcountfix $addressed);
-use vars qw($logDate $logold $logcount $logtime $logrepeat);
+use vars qw($logDate $logold $logcount $logtime $logrepeat $running);
 use vars qw(@backlog);
-use vars qw(%param %file);
+use vars qw(%param %file %cache);
 
 require 5.001;
 
@@ -102,7 +102,7 @@ sub openLog {
        &status("Opened logfile $file{log}.");
        LOG->autoflush(1);
     } else {
-       &status("cannot open logfile $file{log}; not logging.");
+       &status("Cannot open logfile ($file{log}); not logging: $!");
     }
 }
 
@@ -189,14 +189,22 @@ sub status {
     my($input) = @_;
     my $status;
 
+    # a way to hook onto status without looping.
+    # todo: find why $channels{undef} is created.
+    if (0 and $running and !$cache{statusSafe}) {
+       &ircCheck();
+    }
+
     if ($input eq $logold) {
        # allow perl flooding
-       $logrepeat++ unless (/!WARN! PERL: Use of uninitialized/);
+       $logrepeat++ unless ($input =~ /PERL: Use of uninitialized/);
 
        # todo: prevent massive repetitive throttling.
        if ($logrepeat >= 3) {
            $logrepeat = 0;
            &status("LOG: repeat throttle.");
+           # we block it to ensure sequence of logging is intact.
+           # could go with $conn->schedule but that's evil :)
            sleep 1;
        }
     } else {
@@ -217,15 +225,21 @@ sub status {
 
     # Something is using this w/ NULL.
     if (!defined $input or $input =~ /^\s*$/) {
-       $input = "Blank status call? HELP HELP HELP";
+       $input = "ERROR: Blank status call? HELP HELP HELP";
     }
 
     for ($input) {
        s/\n+$//;
-       s/\n/<NL>/g;
        s/\002|037//g;  # bold,video,underline => remove.
     }
 
+    # does this work?
+    if ($input =~ /\n/) {
+       foreach (split(/\n/, $input)) {
+           &status($_);
+       }
+    }
+
     # pump up the stats.
     $statcount++;
 
@@ -276,12 +290,13 @@ sub status {
 
     if (&IsParam("VERBOSITY")) {
        if ($statcountfix) {
-           printf $_red."!%5d!".$ob." ", $statcount;
+           printf $_red."!%6d!".$ob." ", $statcount;
        } else {
-           printf $_green."[%5d]".$ob." ", $statcount;
+           printf $_green."[%6d]".$ob." ", $statcount;
        }
 
-       # three uberstabs to Derek Moeller.
+       # three uberstabs to Derek Moeller. I don't remember why but he
+       # deserved it :)
        my $printable = $input;
 
        if ($printable =~ s/^(<\/\S+>) //) {
@@ -340,19 +355,19 @@ sub status {
        my $newlogDate = sprintf("%04d%02d%02d",$year+1900,$month+1,$day);
        if (defined $logDate and $newlogDate != $logDate) {
            &closeLog();
-           &compress($file{log});
+           &compress( $file{log} );
            &openLog();
        }
     } else {
        $date   = $time;
     }
 
-    print LOG sprintf("%s %s\n", $date, $input);
+    printf LOG "%s %s\n", $date, $input;
 }
 
 sub openSQLDebug {
     if (!open(SQLDEBUG, ">>$param{'SQLDebug'}")) {
-       &ERROR("cannot open $param{'SQLDebug'}...");
+       &ERROR("Cannot open ($param{'SQLDebug'}): $!");
        delete $param{'SQLDebug'};
        return 0;
     }
@@ -367,4 +382,12 @@ sub closeSQLDebug {
     &status("Closed SQL Debug file: $param{'SQLDebug'}");
 }
 
+sub SQLDebug {
+    return unless (&IsParam("SQLDebug"));
+
+    return unless (fileno SQLDEBUG);
+
+    print SQLDEBUG $_[0]."\n";
+}
+
 1;