2012-06-22 11:38:01 +02:00
|
|
|
#!perl -w
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
warn - Default logging plugin for qpsmtpd
|
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
A qpsmtpd plugin which replicates the built in logging functionality, which
|
|
|
|
is to send all logging messages to STDERR below a specific log level.
|
|
|
|
|
|
|
|
It demonstrates that a logging plugin can call ->log itself as well
|
|
|
|
as how to ignore log entries from itself
|
|
|
|
|
|
|
|
=head1 INSTALL AND CONFIG
|
|
|
|
|
|
|
|
Place this plugin in the plugin/logging directory beneath the standard
|
|
|
|
qpsmtpd installation. Edit the config/logging file and add a line like
|
|
|
|
this:
|
|
|
|
|
|
|
|
logging/warn [loglevel]
|
|
|
|
|
|
|
|
where the optional parameters C<loglevel> is either the numeric or text
|
|
|
|
representation of the maximum log level, as shown in the
|
|
|
|
L<config.sample/loglevel> file.
|
|
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
|
|
|
|
John Peacock <jpeacock@cpan.org>
|
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE
|
|
|
|
|
|
|
|
Copyright (c) 2005 John Peacock
|
|
|
|
|
|
|
|
This plugin is licensed under the same terms as the qpsmtpd package itself.
|
|
|
|
Please see the LICENSE file included with qpsmtpd for details.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
sub register {
|
2013-04-21 06:50:39 +02:00
|
|
|
my ($self, $qp, $loglevel) = @_;
|
|
|
|
|
|
|
|
$self->{_level} = LOGWARN;
|
|
|
|
if (defined($loglevel)) {
|
|
|
|
if ($loglevel =~ /^\d+$/) {
|
|
|
|
$self->{_level} = $loglevel;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$self->{_level} = log_level($loglevel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# If you want to capture this log entry with this plugin, you need to
|
|
|
|
# wait until after you register the plugin
|
|
|
|
$self->log(LOGINFO, 'Initializing logging::warn plugin');
|
2012-06-22 11:38:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub hook_logging {
|
2013-04-21 06:50:39 +02:00
|
|
|
my ($self, $transaction, $trace, $hook, $plugin, @log) = @_;
|
2012-06-22 11:38:01 +02:00
|
|
|
|
2013-04-21 06:50:39 +02:00
|
|
|
# Don't log your own log entries! If this is the only logging plugin
|
|
|
|
# then these lines will not be logged at all. You can safely comment
|
|
|
|
# out this line and it will not cause an infinite loop.
|
2012-06-22 11:38:01 +02:00
|
|
|
return DECLINED if defined $plugin && $plugin eq $self->plugin_name;
|
|
|
|
|
|
|
|
return DECLINED if $trace > $self->{_level};
|
|
|
|
|
2013-04-21 06:50:39 +02:00
|
|
|
my $prefix =
|
|
|
|
defined $plugin && defined $hook ? " ($hook) $plugin:"
|
|
|
|
: defined $plugin ? " $plugin:"
|
|
|
|
: defined $hook ? " ($hook) running plugin:"
|
|
|
|
: '';
|
2012-06-22 11:38:01 +02:00
|
|
|
|
|
|
|
warn join(' ', $$ . $prefix, @log), "\n";
|
|
|
|
|
|
|
|
return DECLINED;
|
|
|
|
}
|
|
|
|
|