ChangeLog for Log-Contextual
+ - Add levels_upto RT58558
- Use Log::Log4perl 1.29 to clean up caller stuff
0.00300 2010-06-03
$self->{$_} = 1 for @{$args->{levels}};
$self->{coderef} = $args->{coderef} || sub { print STDERR @_};
+
+ if (my $upto = $args->{levels_upto}) {
+
+ my @levels = (qw( trace debug info warn error fatal ));
+ my $i = 0;
+ for (@levels) {
+ last if $upto eq $_;
+ $i++
+ }
+ for ($i..$#levels) {
+ $self->{$levels[$_]} = 1
+ }
+
+ }
return $self;
}
=head2 new
-Arguments: C<< Dict[ levels => ArrayRef[Str], coderef => Optional[CodeRef] ] $conf >>
+Arguments: C<< Dict[
+ levels => Optional[ArrayRef[Str]],
+ levels_upto => Level,
+ coderef => Optional[CodeRef],
+] $conf >>
my $l = Log::Contextual::SimpleLogger->new({
- levels => [qw( info warn )],
+ levels => [qw( info warn )],
coderef => sub { print @_ }, # the default prints to STDERR
});
+or
+
+ my $l = Log::Contextual::SimpleLogger->new({
+ levels_upto => 'debug',
+ coderef => sub { print @_ }, # the default prints to STDERR
+ });
+
Creates a new SimpleLogger object with the passed levels enabled and optionally
a C<CodeRef> may be passed to modify how the logs are output/stored.
+C<levels_upto> enables all the levels upto and including the level passed.
+
Levels may contain:
trace
coderef => sub { $response = $_[0] },
});
{
- local $SIG{__WARN__} = sub {}; # do this just to hide warning for tests
- set_logger($l2);
+ local $SIG{__WARN__} = sub {}; # do this just to hide warning for tests
+ set_logger($l2);
}
log_trace { 'trace' };
is($response, "[trace] trace\n", 'trace renders correctly');
log_debug { 'line 1', 'line 2' };
is($response, "[debug] line 1\nline 2\n", 'multiline log renders correctly');
+my $u = Log::Contextual::SimpleLogger->new({levels_upto => 'debug'});
+
+ok(!$u->is_trace, 'is_trace is false on SimpleLogger');
+ok($u->is_debug, 'is_debug is true on SimpleLogger');
+ok($u->is_info, 'is_info is true on SimpleLogger');
+ok($u->is_warn, 'is_warn is true on SimpleLogger');
+ok($u->is_error, 'is_error is true on SimpleLogger');
+ok($u->is_fatal, 'is_fatal is true on SimpleLogger');
+