From 6031e49da81dffc1af6eb4d71cd897bfde9dde4e Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Fri, 4 May 2012 14:12:46 -0400 Subject: [PATCH] improved readability of default logging logic --- lib/Qpsmtpd.pm | 22 +++++++++++----------- plugins/logging/warn | 17 +++++++++-------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/lib/Qpsmtpd.pm b/lib/Qpsmtpd.pm index dbbd2a0..e5196d1 100644 --- a/lib/Qpsmtpd.pm +++ b/lib/Qpsmtpd.pm @@ -125,17 +125,18 @@ sub varlog { $self->load_logging; # in case we don't have this loaded yet - my ($rc) = $self->run_hooks_no_respond("logging", $trace, $hook, $plugin, @log); + my ($rc) = $self->run_hooks_no_respond("logging", $trace, $hook, $plugin, @log) + or return; - unless ( $rc and $rc == DECLINED or $rc == OK ) { - # no logging plugins registered so fall back to STDERR - warn join(" ", $$ . - (defined $plugin && defined $hook ? " $plugin plugin ($hook):" : - defined $plugin ? " $plugin plugin:" : - defined $hook ? " running plugin ($hook):" : ""), - @log), "\n" - if $trace <= $TraceLevel; - } + return if $rc == DECLINED || $rc == OK; # plugin success + return if $trace > $TraceLevel; + + # no logging plugins registered, fall back to STDERR + my $prefix = defined $plugin && defined $hook ? " $plugin plugin ($hook):" : + defined $plugin ? " $plugin plugin:" : + defined $hook ? " running plugin ($hook):" : ''; + + warn join(' ', $$ . $prefix, @log), "\n"; } sub clear_config_cache { @@ -515,7 +516,6 @@ sub hook_responder { my ($self, $hook, $msg, $args) = @_; #my $t1 = $SAMPLER->("hook_responder", undef, 1); - my $code = shift @$msg; my $responder = $hook . '_respond'; diff --git a/plugins/logging/warn b/plugins/logging/warn index 204ffdb..d62997b 100644 --- a/plugins/logging/warn +++ b/plugins/logging/warn @@ -28,16 +28,17 @@ sub hook_logging { # 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; + return DECLINED if defined $plugin && $plugin eq $self->plugin_name; - warn - join(" ", $$ . - (defined $plugin ? " $plugin plugin:" : - defined $hook ? " running plugin ($hook):" : ""), - @log), "\n" - if ($trace <= $self->{_level}); + return DECLINED if $trace > $self->{_level}; - return DECLINED; + my $prefix = defined $plugin && defined $hook ? " $plugin plugin ($hook):" : + defined $plugin ? " $plugin plugin:" : + defined $hook ? " running plugin ($hook):" : ''), + + warn join(' ', $$ . $prefix, @log), "\n"; + + return DECLINED; } =head1 NAME