diff --git a/lib/Qpsmtpd/Plugin.pm b/lib/Qpsmtpd/Plugin.pm index ef8b2c1..a92ca78 100644 --- a/lib/Qpsmtpd/Plugin.pm +++ b/lib/Qpsmtpd/Plugin.pm @@ -32,23 +32,24 @@ sub register_hook { die $plugin->plugin_name . ": Invalid hook: $hook" unless $hooks{$hook}; - $plugin->{_qp}->log(LOGDEBUG, $plugin->plugin_name, "hooking", $hook) - unless $hook =~ /logging/; # can't log during load_logging() + if ($hook !~ /logging/) { # can't log during load_logging() + $plugin->{_qp}->log(LOGDEBUG, $plugin->plugin_name, 'hooking', $hook); + } # I can't quite decide if it's better to parse this code ref or if # we should pass the plugin object and method name ... hmn. $plugin->qp->_register_hook( $hook, { - code => sub { - local $plugin->{_qp} = shift; - local $plugin->{_hook} = $hook; - $plugin->$method(@_); - }, - name => $plugin->plugin_name, + code => sub { + local $plugin->{_qp} = shift; + local $plugin->{_hook} = $hook; + $plugin->$method(@_); + }, + name => $plugin->plugin_name, }, $unshift, - ); + ); } sub _register { diff --git a/plugins/logging/file b/plugins/logging/file index 7c82bf7..80495b3 100644 --- a/plugins/logging/file +++ b/plugins/logging/file @@ -230,7 +230,9 @@ sub maybe_reopen { unless ($self->open_log($new_output, $transaction)) { return undef; } - $transaction->notes('file-reopened-this-session', 1); + if (UNIVERSAL::can($transaction,'isa')) { + $transaction->notes('file-reopened-this-session', 1); + } return 1; } return 0; @@ -262,10 +264,12 @@ sub hook_disconnect { sub hook_logging { my ($self, $transaction, $trace, $hook, $plugin, @log) = @_; - return DECLINED - if !defined $self->{_loglevel} - or $trace > $self->{_loglevel}; - return DECLINED if defined $plugin and $plugin eq $self->plugin_name; + if (!defined $self->{_loglevel}) { return DECLINED; } + if ($trace > $self->{_loglevel}) { return DECLINED; } + + if (defined $plugin && $plugin eq $self->plugin_name) { + return DECLINED; + } # Possibly reopen the log iff: # - It's not already open @@ -280,7 +284,9 @@ sub hook_logging { unless (defined $self->maybe_reopen($transaction)) { return DECLINED; } - $transaction->notes('file-logged-this-session', 1) if $transaction; + if (UNIVERSAL::can($transaction,'isa')) { + $transaction->notes('file-logged-this-session', 1) if $transaction; + } } my $f = $self->{_f}; diff --git a/t/config/plugins b/t/config/plugins index c4b4d79..038bd94 100644 --- a/t/config/plugins +++ b/t/config/plugins @@ -1,11 +1,17 @@ # -# Example configuration file for plugins +# Test configuration file for plugins # # enable this to get configuration via http; see perldoc # plugins/http_config for details. # http_config http://localhost/~smtpd/config/ http://www.example.com/smtp.pl?config= +logging/syslog +logging/warn +logging/file t/tmp/test-warn.log + +content_log + # hosts_allow does not work with the tcpserver deployment model! # perldoc plugins/hosts_allow for an alternative. # @@ -13,7 +19,6 @@ # my $MAXCONNIP = 5; # max simultaneous connections from one IP # settings... without this it will NOT refuse more than $MAXCONNIP connections # from one IP! -content_log hosts_allow # information plugins diff --git a/t/qpsmtpd.t b/t/qpsmtpd.t index 308f821..f0c461b 100644 --- a/t/qpsmtpd.t +++ b/t/qpsmtpd.t @@ -141,7 +141,8 @@ sub __log { warn @_; } }; - ok($qp->log(LOGWARN, "test log message"), 'log'); + $qp->log(LOGWARN, "test log message"); + ok(-f 't/tmp/test-warn.log', 'log'); is($warned, "$$ test log message\n", 'LOGWARN emitted correct warning'); }