Support custom timestamp formats
git-svn-id: https://svn.perl.org/qpsmtpd/trunk@735 958fd67b-6ff1-0310-b445-bb7760255be9
This commit is contained in:
parent
8009a316c6
commit
5c71daf274
@ -17,13 +17,14 @@ configuration file:
|
|||||||
|
|
||||||
=over
|
=over
|
||||||
|
|
||||||
logging/file [loglevel I<level>] [reopen] [nosplit] I<path>
|
logging/file [loglevel I<level>] [reopen] [nosplit] [tsformat I<format>] I<path>
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
logging/file loglevel LOGINFO /var/log/qpsmtpd.log
|
logging/file loglevel LOGINFO /var/log/qpsmtpd.log
|
||||||
logging/file /var/log/qpsmtpd.log.%Y-%m-%d
|
logging/file /var/log/qpsmtpd.log.%Y-%m-%d
|
||||||
logging/file loglevel LOGCRIT reopen |/usr/local/sbin/page-sysadmin
|
logging/file loglevel LOGCRIT reopen |/usr/local/sbin/page-sysadmin
|
||||||
|
logging/file loglevel LOGDEBUG tsformat %FT%T /var/log/qpsmtpd.log
|
||||||
|
|
||||||
=back
|
=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
|
example, if LOGWARN were selected, LOGERROR, LOGCRIT and LOGEMERG messages
|
||||||
would be logged as well).
|
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
|
=over
|
||||||
|
|
||||||
=item B<LOGDEBUG>
|
=item B<LOGDEBUG>
|
||||||
@ -121,6 +128,7 @@ sub register {
|
|||||||
my %args;
|
my %args;
|
||||||
|
|
||||||
$self->{_loglevel} = LOGWARN;
|
$self->{_loglevel} = LOGWARN;
|
||||||
|
$self->{_tsformat} = '%a %b %d %T %Y'; # same as scalar localtime
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
last if !@args;
|
last if !@args;
|
||||||
@ -147,6 +155,11 @@ sub register {
|
|||||||
shift @args;
|
shift @args;
|
||||||
$self->{_reopen} = 1;
|
$self->{_reopen} = 1;
|
||||||
}
|
}
|
||||||
|
elsif (lc $args[0] eq 'tsformat') {
|
||||||
|
shift @args;
|
||||||
|
my $format = shift @args;
|
||||||
|
$self->{_tsformat} = $format;
|
||||||
|
}
|
||||||
else { last }
|
else { last }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,7 +273,8 @@ sub hook_logging {
|
|||||||
}
|
}
|
||||||
|
|
||||||
my $f = $self->{_f};
|
my $f = $self->{_f};
|
||||||
print $f scalar localtime, ' ', hostname(), '[', $$, ']: ', @log, "\n";
|
print $f strftime($self->{_tsformat}, localtime), ' ',
|
||||||
|
hostname(), '[', $$, ']: ', @log, "\n";
|
||||||
return DECLINED;
|
return DECLINED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user