Support custom timestamp formats

git-svn-id: https://svn.perl.org/qpsmtpd/trunk@735 958fd67b-6ff1-0310-b445-bb7760255be9
This commit is contained in:
Matt Sergeant 2007-05-17 20:32:43 +00:00
parent 8009a316c6
commit 5c71daf274

View File

@ -17,13 +17,14 @@ configuration file:
=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 @@ given should be chosen from the list below. Priorities count downward (for
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 @@ sub register {
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 @@ sub register {
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 @@ sub hook_logging {
}
my $f = $self->{_f};
print $f scalar localtime, ' ', hostname(), '[', $$, ']: ', @log, "\n";
print $f strftime($self->{_tsformat}, localtime), ' ',
hostname(), '[', $$, ']: ', @log, "\n";
return DECLINED;
}