Debian Codegraph @

plugins/logging/apache

raw
1 #!perl -w
2
3 =head1 NAME
4
5 logging/apache - logging plugin for qpsmtpd which logs to the apache error log
6
7 =cut
8
9 # more POD at the end
10
11 use strict;
12 use warnings FATAL => 'all';
13 use Apache2::Log;
14 use Apache2::RequestUtil ();
15
16 use Qpsmtpd::Constants;
17
18 sub register {
19 my ($self, $qp) = @_;
20
21 die "Not running under Apache::Qpsmtpd"
22 unless ($qp->{conn} && $qp->{conn}->isa('Apache2::Connection'));
23
24 my $rr = Apache2::RequestRec->new($self->qp->{conn});
25 $self->{_log} = $rr->log
26 if $rr;
27
28 $self->log(LOGINFO, 'Initializing logging::apache plugin');
29 }
30
31 sub hook_logging {
32 my ($self, $transaction, $trace, $hook, $plugin, @log) = @_;
33
34 # Don't log your own log entries! If this is the only logging plugin
35 # then these lines will not be logged at all. You can safely comment
36 # out this line and it will not cause an infinite loop.
37 return DECLINED if defined $plugin and $plugin eq $self->plugin_name;
38
39 unless ($self->{_log}) {
40 my $rr = Apache2::RequestRec->new($self->qp->{conn});
41 unless ($rr) {
42 warn "no Apache2::RequestRec?... logmsg was: ", join(" ", @log);
43 return DECLINED;
44 }
45 $self->{_log} = $rr->log;
46 }
47
48 # luckily apache uses the same log levels as qpsmtpd...
49 ($trace = lc Qpsmtpd::Constants::log_level($trace)) =~ s/^log//;
50 $trace = 'emerg' # ... well, nearly...
51 if $trace eq 'radar';
52
53 my $log = $self->{_log};
54 unless ($log->can($trace)) { # ... but you never know if it changes
55 $log->emerg("Can't log with level '$trace', logmsg was: ",
56 join(" ", @log));
57 return DECLINED;
58 }
59
60 $log->$trace(
61 join(
62 " ",
63 $$
64 . (
65 defined $plugin ? " $plugin plugin:"
66 : defined $hook ? " running plugin ($hook):"
67 : ""
68 ),
69 @log
70 )
71 ); # no \n at the end!
72
73 return DECLINED;
74 }
75
76 =head1 DESCRIPTION
77
78 The logging/apache plugin uses the apache logging mechanism to write its
79 messages to the apache error log.
80
81 =head1 INSTALL AND CONFIG
82
83 Place this plugin in the plugin/logging directory beneath the standard
84 qpsmtpd installation. Edit the config/logging file and add a line like
85 this:
86
87 logging/apache
88
89 To change what is shown in the logs, change the I<LogLevel> directive in
90 the virtual host config for Qpsmtpd and maybe change the I<ErrorLog> log
91 file:
92
93 <VirtualHost _default_:25>
94 PerlSetVar QpsmtpdDir /path/to/qpsmtpd
95 PerlModule Apache::Qpsmtpd
96 PerlProcessConnectionHandler Apache::Qpsmtpd
97 LogLevel debug
98 ErrorLog /var/log/apache2/qpsmtpd.log
99 </VirtualHost>
100
101 =head1 AUTHOR
102
103 Hanno Hecker <[email protected]>
104
105 =head1 COPYRIGHT AND LICENSE
106
107 Copyright (c) 2007 Hanno Hecker
108
109 This plugin is licensed under the same terms as the qpsmtpd package itself.
110 Please see the LICENSE file included with qpsmtpd for details.
111
112 =cut
113