use warnings;
{
- for my $name (qw[ trace debug info warn error fatal ]) {
+ for my $name (qw( trace debug info warn error fatal )) {
no strict 'refs';
$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;
}
=head1 SYNOPSIS
- use Log::Contextual qw{:log},
- -logger => Log::Contextual::SimpleLogger->new({ levels => [qw{debug}]});
+ use Log::Contextual::SimpleLogger;
+ use Log::Contextual qw( :log ),
+ -logger => Log::Contextual::SimpleLogger->new({ levels => [qw( debug )]});
log_info { 'program started' }; # no-op because info is not in levels
sub foo {
=head2 new
-Arguments: 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
=head2 $level
-Arguments: @anything
+Arguments: C<@anything>
All of the following six methods work the same. The basic pattern is: