Author: vetinari
Date: Sun Aug 5 05:00:44 2007
New Revision: 767
Added:
contrib/vetinari/logging_apache
Log:
logging/apache - logging plugin which logs to the apache error log
Added: contrib/vetinari/logging_apache
==============================================================================
--- (empty file)
+++ contrib/vetinari/logging_apache Sun Aug 5 05:00:44 2007
@@ -0,0 +1,108 @@
+#!/usr/bin/perl
+#
+
+=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'
+ 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 loggin/apache plugin uses the apache logging mechanism to write it's
+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<LogLevel> directive in
+the virtual host config for Qpsmtpd and maybe change the I<ErrorLog> log
+file:
+
+ <VirtualHost _default_:25>
+ PerlSetVar QpsmtpdDir /path/to/qpsmtpd
+ PerlModule Apache::Qpsmtpd
+ PerlProcessConnectionHandler Apache::Qpsmtpd
+ LogLevel debug
+ ErrorLog /var/log/apache2/qpsmtpd.log
+ </VirtualHost>
+
+=head1 AUTHOR
+
+Hanno Hecker <[EMAIL PROTECTED]>
+
+=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
+