develooper Front page | perl.cvs.qpsmtpd | Postings from May 2007

[svn:qpsmtpd] r735 - trunk/plugins/logging

From:
msergeant
Date:
May 17, 2007 13:32
Subject:
[svn:qpsmtpd] r735 - trunk/plugins/logging
Message ID:
20070517203244.9ECFCCB9B8@x12.develooper.com
Author: msergeant
Date: Thu May 17 13:32:43 2007
New Revision: 735

Modified:
   trunk/plugins/logging/file

Log:
Support custom timestamp formats


Modified: trunk/plugins/logging/file
==============================================================================
--- trunk/plugins/logging/file	(original)
+++ trunk/plugins/logging/file	Thu May 17 13:32:43 2007
@@ -17,13 +17,14 @@
 
 =over
 
-logging/file [loglevel I<level>] [reopen] [nosplit] I<path>
+logging/file [loglevel I<level>] [reopen] [nosplit] [tsformat I<format>] I<path>
 
 For example:
 
 logging/file loglevel LOGINFO /var/log/qpsmtpd.log
 logging/file /var/log/qpsmtpd.log.%Y-%m-%d
 logging/file loglevel LOGCRIT reopen |/usr/local/sbin/page-sysadmin
+logging/file loglevel LOGDEBUG tsformat %FT%T /var/log/qpsmtpd.log
 
 =back
 
@@ -68,6 +69,12 @@
 example, if LOGWARN were selected, LOGERROR, LOGCRIT and LOGEMERG messages
 would be logged as well).
 
+=item tsformat I<format>
+
+By default qpsmtpd will prepend log items with the date and time as given in
+the format by perl's C<localtime()> function. If you prefer another format then
+you can specify a tsformat parameter.
+
 =over
 
 =item B<LOGDEBUG>
@@ -121,6 +128,7 @@
     my %args;
 
     $self->{_loglevel} = LOGWARN;
+    $self->{_tsformat} = '%a %b %d %T %Y'; # same as scalar localtime
 
     while (1) {
     	last if !@args;
@@ -147,6 +155,11 @@
 		shift @args;
 		$self->{_reopen} = 1;
 	}
+	    elsif (lc $args[0] eq 'tsformat') {
+	        shift @args;
+	        my $format = shift @args;
+	        $self->{_tsformat} = $format;
+	    }
         else { last }
     }
 
@@ -260,7 +273,8 @@
     }
 
     my $f = $self->{_f};
-    print $f scalar localtime, ' ', hostname(), '[', $$, ']: ', @log, "\n";
+    print $f strftime($self->{_tsformat}, localtime), ' ',
+             hostname(), '[', $$, ']: ', @log, "\n";
     return DECLINED;
 }
 



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About