From fe4f40b560c2c73e74221f382a20e3ef3b9d713a Mon Sep 17 00:00:00 2001 From: Hanno Hecker Date: Mon, 2 Mar 2009 20:08:27 +0100 Subject: [PATCH] "new" plugin logging/apache from SVN's contrib/ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Imported logging/apache from SVN's contrib. Changes: * perltidy run * Minor tidy-ups by Ask Signed-off-by: Ask Bjørn Hansen --- Changes | 2 + plugins/logging/apache | 115 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 plugins/logging/apache diff --git a/Changes b/Changes index 16b2c44..ab549d5 100644 --- a/Changes +++ b/Changes @@ -1,4 +1,6 @@ + Add logging/apache plugin for logging to the apache error log + Add connection_time plugin Add rcpt_regexp plugin (Hanno Hecker) diff --git a/plugins/logging/apache b/plugins/logging/apache new file mode 100644 index 0000000..11168e9 --- /dev/null +++ b/plugins/logging/apache @@ -0,0 +1,115 @@ + +=head1 NAME + +logging/apache - logging plugin for qpsmtpd which logs to the apache error log + +=cut + +# more POD at the end + +use strict; +use warnings FATAL => 'all'; +use Apache2::Log; +use Apache2::RequestUtil (); + +use Qpsmtpd::Constants; + +sub register { + my ($self, $qp) = @_; + + die "Not running under Apache::Qpsmtpd" + unless ($qp->{conn} && $qp->{conn}->isa('Apache2::Connection')); + + my $rr = Apache2::RequestRec->new($self->qp->{conn}); + $self->{_log} = $rr->log + if $rr; + + $self->log(LOGINFO, 'Initializing logging::apache plugin'); +} + +sub hook_logging { + my ($self, $transaction, $trace, $hook, $plugin, @log) = @_; + + # 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. + return DECLINED if defined $plugin and $plugin eq $self->plugin_name; + + unless ($self->{_log}) { + my $rr = Apache2::RequestRec->new($self->qp->{conn}); + unless ($rr) { + warn "no Apache2::RequestRec?... logmsg was: ", join(" ", @log); + return DECLINED; + } + $self->{_log} = $rr->log; + } + + # luckily apache uses the same log levels as qpsmtpd... + ($trace = lc Qpsmtpd::Constants::log_level($trace)) =~ s/^log//; + $trace = 'emerg' # ... well, nearly... + if $trace eq 'radar'; + + my $log = $self->{_log}; + unless ($log->can($trace)) { # ... but you never know if it changes + $log->emerg("Can't log with level '$trace', logmsg was: ", + join(" ", @log)); + return DECLINED; + } + + $log->$trace( + join( + " ", + $$ + . ( + defined $plugin ? " $plugin plugin:" + : defined $hook ? " running plugin ($hook):" + : "" + ), + @log + ) + ); # no \n at the end! + + return DECLINED; +} + +=cut + +=head1 DESCRIPTION + +The logging/apache plugin uses the apache logging mechanism to write its +messages to the apache error log. + +=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/apache + +To change what is shown in the logs, change the I directive in +the virtual host config for Qpsmtpd and maybe change the I log +file: + + + PerlSetVar QpsmtpdDir /path/to/qpsmtpd + PerlModule Apache::Qpsmtpd + PerlProcessConnectionHandler Apache::Qpsmtpd + LogLevel debug + ErrorLog /var/log/apache2/qpsmtpd.log + + +=head1 AUTHOR + +Hanno Hecker + +=head1 COPYRIGHT AND LICENSE + +Copyright (c) 2007 Hanno Hecker + +This plugin is licensed under the same terms as the qpsmtpd package itself. +Please see the LICENSE file included with qpsmtpd for details. + +=cut + +# vim: ts=4 sw=4 expandtab syn=perl