X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Flogger.pl;h=6e80e6c181576ded12197b77327789decaa0c50a;hb=4a83aa7e972adb3187deed477d570d46412b9327;hp=bcf767341fc7d03a148bca86193d10a48b20c7ad;hpb=b0ed64e5f19d957102c6e73fc79b06801c1a4ecc;p=infobot.git diff --git a/src/logger.pl b/src/logger.pl index bcf7673..6e80e6c 100644 --- a/src/logger.pl +++ b/src/logger.pl @@ -43,7 +43,7 @@ use vars qw($b_black $_black $b_red $_red $b_green $_green $b_yellow $_yellow $b_blue $_blue $b_magenta $_magenta $b_cyan $_cyan $b_white $_white $_reset $_bold $ob $b); -$b_black = cl('bold black'); $_black = cl('black'); +$b_black = cl('bold black'); $_black = cl('black'); $b_red = cl('bold red'); $_red = cl('red'); $b_green = cl('bold green'); $_green = cl('green'); $b_yellow = cl('bold yellow'); $_yellow = cl('yellow'); @@ -93,7 +93,7 @@ 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); - $file{log} .= "-".$logDate; + $file{log} .= $logDate; } if (open(LOG, ">>$file{log}")) { @@ -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. @@ -228,7 +223,7 @@ sub status { for ($input) { s/\n+$//; - s/\002|037//g; # bold,video,underline => remove. + s/\002|\037//g; # bold,video,underline => remove. } # does this work? @@ -347,6 +342,7 @@ sub status { # remove control characters from logging to LOGFILE. for ($input) { + last if (&IsParam("logColors")); s/\e\[[0-9;]+m//g; # escape codes. s/[\cA-\c_]//g; # control chars. } @@ -370,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'}): $!");