]> diplodocus.org Git - minc/commitdiff
Drop Log::Dispatch (finally) and simplify logging.
authorepg <>
Sun, 11 Apr 2004 21:16:49 +0000 (21:16 +0000)
committerepg <>
Sun, 11 Apr 2004 21:16:49 +0000 (21:16 +0000)
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.

minc

diff --git a/minc b/minc
index f33fddbfd69f777c0e0f8668ec30a6f9dbbf25f1..2313a57c446ab08cece6bf806a1ed6a3f0ed8637 100755 (executable)
--- 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 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;
 use POSIX qw(strftime WEXITSTATUS WIFEXITED);
 
 our $VERSION = 1;
@@ -205,29 +203,7 @@ $ENV{"MHCONTEXT"} = $mh . '/.minc.context';
 ###############################################################################
 # Logging
 
 ###############################################################################
 # 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 {
 sub mylog {
-    my $level = shift;
-    my $act = shift;
     my $timestamp = strftime('%b %e %H:%M:%S', localtime);
     my $msg;
     foreach my $part (@_) {
     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;
     }
     # 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;
 
     my ($text, @contents) = @_;
     my $last;
 
@@ -261,7 +229,7 @@ sub logincoming {
         $last = '';
     }
 
         $last = '';
     }
 
-    mylog('info', INCOMINGCHAR, $text, $last);
+    mylog('<< ', $text, $last);
 }
 
 sub log_headers {
 }
 
 sub log_headers {
@@ -269,10 +237,10 @@ sub log_headers {
 
     # For an explanation of the %headers structure, see the
     # get_headers function below.
 
     # 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'}});
 }
 
 \f
 }
 
 \f
@@ -432,7 +400,7 @@ sub store_message {
     }
 
     if ($mhfolder ne 'SPAM') {
     }
 
     if ($mhfolder ne 'SPAM') {
-        logsave("+$mhfolder");
+        mylog('+', $mhfolder);
     }
 
     if ($run) {
     }
 
     if ($run) {