| 1 |
#!perl -w |
| 2 |
|
| 3 |
=head1 NAME |
| 4 |
|
| 5 |
warn - Default logging plugin for qpsmtpd |
| 6 |
|
| 7 |
=head1 DESCRIPTION |
| 8 |
|
| 9 |
A qpsmtpd plugin which replicates the built in logging functionality, which |
| 10 |
is to send all logging messages to STDERR below a specific log level. |
| 11 |
|
| 12 |
It demonstrates that a logging plugin can call ->log itself as well |
| 13 |
as how to ignore log entries from itself |
| 14 |
|
| 15 |
=head1 INSTALL AND CONFIG |
| 16 |
|
| 17 |
Place this plugin in the plugin/logging directory beneath the standard |
| 18 |
qpsmtpd installation. Edit the config/logging file and add a line like |
| 19 |
this: |
| 20 |
|
| 21 |
logging/warn [loglevel] |
| 22 |
|
| 23 |
where the optional parameters C<loglevel> is either the numeric or text |
| 24 |
representation of the maximum log level, as shown in the |
| 25 |
L<config.sample/loglevel> file. |
| 26 |
|
| 27 |
=head1 AUTHOR |
| 28 |
|
| 29 |
John Peacock <[email protected]> |
| 30 |
|
| 31 |
=head1 COPYRIGHT AND LICENSE |
| 32 |
|
| 33 |
Copyright (c) 2005 John Peacock |
| 34 |
|
| 35 |
This plugin is licensed under the same terms as the qpsmtpd package itself. |
| 36 |
Please see the LICENSE file included with qpsmtpd for details. |
| 37 |
|
| 38 |
=cut |
| 39 |
|
| 40 |
sub register { |
| 41 |
my ($self, $qp, $loglevel) = @_; |
| 42 |
|
| 43 |
$self->{_level} = LOGWARN; |
| 44 |
if (defined($loglevel)) { |
| 45 |
if ($loglevel =~ /^\d+$/) { |
| 46 |
$self->{_level} = $loglevel; |
| 47 |
} |
| 48 |
else { |
| 49 |
$self->{_level} = log_level($loglevel); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
# If you want to capture this log entry with this plugin, you need to |
| 54 |
# wait until after you register the plugin |
| 55 |
$self->log(LOGINFO, 'Initializing logging::warn plugin'); |
| 56 |
} |
| 57 |
|
| 58 |
sub hook_logging { |
| 59 |
my ($self, $transaction, $trace, $hook, $plugin, @log) = @_; |
| 60 |
|
| 61 |
# Don't log your own log entries! If this is the only logging plugin |
| 62 |
# then these lines will not be logged at all. You can safely comment |
| 63 |
# out this line and it will not cause an infinite loop. |
| 64 |
return DECLINED if defined $plugin && $plugin eq $self->plugin_name; |
| 65 |
|
| 66 |
return DECLINED if $trace > $self->{_level}; |
| 67 |
|
| 68 |
my $prefix = |
| 69 |
defined $plugin && defined $hook ? " ($hook) $plugin:" |
| 70 |
: defined $plugin ? " $plugin:" |
| 71 |
: defined $hook ? " ($hook) running plugin:" |
| 72 |
: ''; |
| 73 |
|
| 74 |
warn join(' ', $$ . $prefix, @log), "\n"; |
| 75 |
|
| 76 |
return DECLINED; |
| 77 |
} |
| 78 |
|