Debian Codegraph @

plugins/logging/transaction_id

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