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