[Catalyst-commits] r9922 - in Catalyst-Runtime/5.80/trunk:
lib/Catalyst t
t0m at dev.catalyst.perl.org
t0m at dev.catalyst.perl.org
Tue Apr 28 20:20:19 GMT 2009
Author: t0m
Date: 2009-04-28 21:20:18 +0100 (Tue, 28 Apr 2009)
New Revision: 9922
Modified:
Catalyst-Runtime/5.80/trunk/lib/Catalyst/Log.pm
Catalyst-Runtime/5.80/trunk/t/unit_core_setup_log.t
Log:
Make logging additive properly. No longer WTF.
Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/Log.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/Log.pm 2009-04-28 19:53:24 UTC (rev 9921)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/Log.pm 2009-04-28 20:20:18 UTC (rev 9922)
@@ -6,7 +6,8 @@
use Data::Dump;
use Class::MOP ();
-our %LEVELS = ();
+our %LEVELS = (); # Levels stored as bit field, ergo debug = 1, warn = 2 etc
+our %LEVEL_MATCH = (); # Stored as additive, thus debug = 31, warn = 30 etc
has level => (is => 'rw');
has _body => (is => 'rw');
@@ -16,12 +17,16 @@
my @levels = qw[ debug info warn error fatal ];
my $meta = Class::MOP::get_metaclass_by_name(__PACKAGE__);
- for ( my $i = 0 ; $i < @levels ; $i++ ) {
+ my $summed_level = 0;
+ for ( my $i = $#levels ; $i >= 0 ; $i-- ) {
my $name = $levels[$i];
+
my $level = 1 << $i;
-
+ $summed_level |= $level;
+
$LEVELS{$name} = $level;
+ $LEVEL_MATCH{$name} = $summed_level;
$meta->add_method($name, sub {
my $self = shift;
@@ -43,11 +48,7 @@
my $class = shift;
my $self = $class->$orig;
- if (@_ == 1 && $_[0] eq 'debug') {
- $self->levels( keys %LEVELS );
- } else {
- $self->levels( scalar(@_) ? @_ : keys %LEVELS );
- }
+ $self->levels( scalar(@_) ? @_ : keys %LEVELS );
return $self;
};
@@ -61,7 +62,7 @@
sub enable {
my ( $self, @levels ) = @_;
my $level = $self->level;
- for(map { $LEVELS{$_} } @levels){
+ for(map { $LEVEL_MATCH{$_} } @levels){
$level |= $_;
}
$self->level($level);
Modified: Catalyst-Runtime/5.80/trunk/t/unit_core_setup_log.t
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/unit_core_setup_log.t 2009-04-28 19:53:24 UTC (rev 9921)
+++ Catalyst-Runtime/5.80/trunk/t/unit_core_setup_log.t 2009-04-28 20:20:18 UTC (rev 9922)
@@ -34,9 +34,7 @@
$app->setup_log('error,warn');
ok !$app->debug, 'Not in debug mode';
test_log_object($app->log,
- fatal => 0, # WTF - I thought log levels were additive these days,
- # or do I not understand the patch which pupported to make
- # them so?
+ fatal => 1,
error => 1,
warn => 1,
info => 0,
@@ -62,8 +60,8 @@
$app->setup_log('warn');
ok !$app->debug, 'Not In debug mode';
test_log_object($app->log,
- fatal => 0,
- error => 0,
+ fatal => 1,
+ error => 1,
warn => 1,
info => 0,
debug => 0,
@@ -73,16 +71,14 @@
my $app = mock_app('TestLogAppEmptyString');
$app->setup_log('');
ok !$app->debug, 'Not In debug mode';
- TODO: {
- local $TODO = 'THis is insane';
- test_log_object($app->log,
- fatal => 0,
- error => 0,
- warn => 0,
- info => 0,
- debug => 0,
- );
- }
+ # Note that by default, you get _all_ the log levels turned on
+ test_log_object($app->log,
+ fatal => 1,
+ error => 1,
+ warn => 1,
+ info => 1,
+ debug => 1,
+ );
}
{
my $app = mock_app('TestLogAppDebugOnly');
More information about the Catalyst-commits
mailing list