make sure $transaction->notes is blessed before
calling it as such. It doesn't resolve #199 but it does help there. I'm not sure initializing Qpsmtpd::transaction as {} is a brilliant idea, but I haven't a better solution for that yet.
This commit is contained in:
parent
0d79c1ef8e
commit
d9ac50f383
@ -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 {
|
||||
|
@ -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};
|
||||
|
@ -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
|
||||
|
@ -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');
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user