From: epg <> Date: Sun, 11 Apr 2004 21:16:49 +0000 (+0000) Subject: Drop Log::Dispatch (finally) and simplify logging. X-Git-Url: https://diplodocus.org/git/minc/commitdiff_plain/2ef74b018653979ae971a001507ae845ebe373e4?hp=cf3b28b73d3290251efa6f76ca72be2a50bd5e76 Drop Log::Dispatch (finally) and simplify logging. Kill global constants LOG_DEBUGLEVEL, SCREEN_DEBUGLEVEL, DEBUGCHAR, INFOCHAR, INCOMINGCHAR, SAVECHAR, WARNCHAR, ERRORCHAR. Kill global $logger and functions logsave, loginfo, logdebug, logwarn, logerr. (mylog): Kill first two parameters; all @_ are now catenated for the log message. Simply open $logfile and write the timestamp and message, no more. (logheader): Renamed from logincoming. Adapt to new mylog. (log_headers): s/logincoming/logheader/ (store_message): Call mylog instead of logsave. --- diff --git a/minc b/minc index f33fddb..2313a57 100755 --- a/minc +++ b/minc @@ -31,8 +31,6 @@ use Fcntl qw(O_WRONLY O_EXCL O_CREAT); use FileHandle; use File::stat; use Getopt::Std; $Getopt::Std::STANDARD_HELP_VERSION = 1; -use Log::Dispatch; -use Log::Dispatch::File; use POSIX qw(strftime WEXITSTATUS WIFEXITED); our $VERSION = 1; @@ -205,29 +203,7 @@ $ENV{"MHCONTEXT"} = $mh . '/.minc.context'; ############################################################################### # Logging -# debuglevels for the logger -use constant LOG_DEBUGLEVEL => 'info'; -use constant SCREEN_DEBUGLEVEL => 'debug'; - -# characters used to wrap around the id field in the log so I can more -# easily parse the msg flow -use constant DEBUGCHAR => '%'; -use constant INFOCHAR => '='; -use constant INCOMINGCHAR => '<'; -use constant SAVECHAR => '>'; -use constant WARNCHAR => 'W'; -use constant ERRORCHAR => 'E'; - -my $logger = new Log::Dispatch; -$logger->add(new Log::Dispatch::File (name=>'logfile', - filename=>$logfile, - min_level=>'info', - mode=>'append')); - -# log alias, handles getting passed vars that are undef sub mylog { - my $level = shift; - my $act = shift; my $timestamp = strftime('%b %e %H:%M:%S', localtime); my $msg; foreach my $part (@_) { @@ -237,21 +213,13 @@ sub mylog { } # no newlines in the log message, thanks $msg =~ s/\n/ /gm; - $msg = sprintf("%s %s%s %s\n", $timestamp, $act, $act, $msg); - $logger->log(level=>$level, message=>$msg); - if ($act eq SAVECHAR) { - $logger->log(level=>$level, message=>"\n"); - } + open(LOG, ">>$logfile") or die("open(>>$logfile): $!"); + print(LOG "$timestamp $msg\n") or die("print(>>$logfile): $!"); + close(LOG) or die("close($logfile): $!"); } -sub logsave { mylog('notice', SAVECHAR, @_); } -sub loginfo { mylog('info', INFOCHAR, @_); } -sub logdebug { mylog('debug', DEBUGCHAR, @_); } -sub logwarn { mylog('warning', WARNCHAR, @_); } -sub logerr { mylog('error', ERRORCHAR, @_); } - -sub logincoming { +sub logheader { my ($text, @contents) = @_; my $last; @@ -261,7 +229,7 @@ sub logincoming { $last = ''; } - mylog('info', INCOMINGCHAR, $text, $last); + mylog('<< ', $text, $last); } sub log_headers { @@ -269,10 +237,10 @@ sub log_headers { # For an explanation of the %headers structure, see the # get_headers function below. - logincoming('From: ', @{$headers{'return-path'}}); - logincoming('To: ', @{$headers{'to'}}); - logincoming('Subject: ', @{$headers{'subject'}}); - logincoming('Message-Id: ', @{$headers{'message-id'}}); + logheader('From: ', @{$headers{'return-path'}}); + logheader('To: ', @{$headers{'to'}}); + logheader('Subject: ', @{$headers{'subject'}}); + logheader('Message-Id: ', @{$headers{'message-id'}}); } @@ -432,7 +400,7 @@ sub store_message { } if ($mhfolder ne 'SPAM') { - logsave("+$mhfolder"); + mylog('+', $mhfolder); } if ($run) {