Subject: | Make appender_thresholds_adjust return number of appenders changed |
Make appender_thresholds_adjust return number of appenders changed.
The motivation is to be able to detect failure to change any appender:
Log::Log4perl->appender_thresholds_adjust(1)
or die("failed to adjust threshold")
This will typically happen if Log::Log4perl is not initialized at the
time appender_thresholds_adjust is called.
See attached patches:
Log4perl.pm.patch
021AppThres.t.patch
Thanks for continuing to provide an excellent logging framework.
Best regards,
Andreas
Subject: | 021AppThres.t.patch |
--- Log-Log4perl-1.20/t/021AppThres.t 2004-11-30 23:11:13.000000000 +0100
+++ Log-Log4perl-1.20/t/021AppThres.t.new 2009-02-19 12:29:07.000000000 +0100
@@ -11,10 +11,14 @@
use Log::Log4perl qw(get_logger);
use Log::Log4perl::Level;
-BEGIN { plan tests => 20 }
+BEGIN { plan tests => 24 }
ok(1); # If we made it this far, we're ok.
+cmp_ok(Log::Log4perl->appender_thresholds_adjust(1), q{==}, 0,
+ q{Expect 0 appenders to be affected before first init since there are none}
+);
+
my $log0 = Log::Log4perl->get_logger("");
my $log1 = Log::Log4perl->get_logger("abc.def");
my $log2 = Log::Log4perl->get_logger("abc.def.ghi");
@@ -186,7 +190,8 @@
is($app0->buffer(), "WARN - Warning\nERROR - Error\n", "appender threshold");
is($app1->buffer(), "ERROR - Error\n", "appender threshold");
-Log::Log4perl->appender_thresholds_adjust(-1);
+cmp_ok(Log::Log4perl->appender_thresholds_adjust(-1),
+ q{==}, 2, q{Expect 2 appenders to be affected});
$app0->buffer("");
$app1->buffer("");
@@ -205,13 +210,15 @@
$app1->buffer("");
# reset previous thresholds
-Log::Log4perl->appender_thresholds_adjust(1);
+cmp_ok(Log::Log4perl->appender_thresholds_adjust(1),
+ q{==}, 2, q{Expect 2 appenders to be affected});
$app0->buffer("");
$app1->buffer("");
# rig just one threshold
-Log::Log4perl->appender_thresholds_adjust(-1, ['BUF0']);
+cmp_ok(Log::Log4perl->appender_thresholds_adjust(-1, ['BUF0']),
+ q{==}, 1, q{Expect 1 appender to be affected});
$logger->more_logging();
$logger->info("Info");
Subject: | Log4perl.pm.patch |
--- Log-Log4perl-1.20/lib/Log/Log4perl.pm 2008-12-10 07:12:33.000000000 +0100
+++ Log-Log4perl-1.20/lib/Log/Log4perl.pm.new 2009-02-19 12:27:52.000000000 +0100
@@ -377,15 +377,17 @@
}
##################################################
+# Return number of appenders changed
sub appender_thresholds_adjust { # Readjust appender thresholds
##################################################
# If someone calls L4p-> and not L4p::
shift if $_[0] eq __PACKAGE__;
my($delta, $appenders) = @_;
+ my $retval = 0;
if($delta == 0) {
# Nothing to do, no delta given.
- return 1;
+ return;
}
if(defined $appenders) {
@@ -415,8 +417,9 @@
$old_thres, -$delta);
}
- $app->threshold($new_thres);
+ ++$retval if ($app->threshold($new_thres) == $new_thres);
}
+ return $retval;
}
##################################################