X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Flogger.pl;fp=src%2Flogger.pl;h=a74602d42a1d9aeab2979d3b3e1cb22b331af7ea;hb=c999e27e22999cea0f2734f6eb64405f237bf705;hp=c7593a7ba064bf374fa87d15ca32ffb8b725fd67;hpb=d17f20654101400a45961d561eaf299a267b9285;p=infobot.git diff --git a/src/logger.pl b/src/logger.pl index c7593a7..a74602d 100644 --- a/src/logger.pl +++ b/src/logger.pl @@ -187,26 +187,21 @@ sub status { my($input) = @_; my $status; - # a way to hook onto status without looping. - # todo: find why $channels{} is created. - if (0 and $running and !$cache{statusSafe}) { - &ircCheck(); + if ($input =~ /PERL: Use of uninitialized/) { + &debug_perl($input); + return; } if ($input eq $logold) { - # allow perl flooding - if ($input !~ /PERL: Use of uninitialized/) { - $logrepeat++; - return; - } - } else { - $logold = $input; + $logrepeat++; + return; + } - # if only I had followed how sysklogd does it, heh. lame me. -xk - if ($logrepeat >= 3) { - &status("LOG: last message repeated $logrepeat times"); - $logrepeat = 0; - } + $logold = $input; + # if only I had followed how sysklogd does it, heh. lame me. -xk + if ($logrepeat >= 3) { + &status("LOG: last message repeated $logrepeat times"); + $logrepeat = 0; } # if it's not a scalar, attempt to warn and fix. @@ -371,6 +366,46 @@ sub status { printf LOG "%s %s\n", $date, $input; } +sub debug_perl { + my ($str) = @_; + + return unless ($str =~ /^WARN: Use of uninitialized value .* at (\S+) line (\d+)/); + my ($file,$line) = ($1,$2); + if (!open(IN,$file)) { + &status("WARN: cannot open $file: $!"); + return; + } + + # todo: better filename. + open(OUT, ">>debug.log"); + print OUT "DEBUG: $str\n"; + + # note: cannot call external functions because SIG{} does not allow us to. + my $i; + while () { + chop; + $i++; + # bleh. this tries to duplicate status(). + # todo: statcountfix + # todo: rename to log_*someshit* + if ($i == $line) { + my $msg = "$file: $i:!$_"; + printf "%s[%6d]%s %s\n", $_green, $statcount, $ob, $msg; + print OUT "DEBUG: $msg\n"; + $statcount++; + next; + } + if ($i+3 > $line && $i-3 < $line) { + my $msg = "$file: $i: $_"; + printf "%s[%6d]%s %s\n", $_green, $statcount, $ob, $msg; + print OUT "DEBUG: $msg\n"; + $statcount++; + } + } + close IN; + close OUT; +} + sub openSQLDebug { if (!open(SQLDEBUG, ">>$param{'SQLDebug'}")) { &ERROR("Cannot open ($param{'SQLDebug'}): $!");