Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is_$level functions #1

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions lib/Log/Log4perl/Tiny.pm
Expand Up @@ -323,10 +323,19 @@ BEGIN {
no strict 'refs';

for my $name (qw( FATAL ERROR WARN INFO DEBUG TRACE )) {

# create the ->level methods
*{__PACKAGE__ . '::' . lc($name)} = sub {
my $self = shift;
return $self->log($$name, @_);
};

# and it ->is_level methods
*{__PACKAGE__ . '::is_' . lc($name)} = sub {
return 0 if $_[0]->{level} == $DEAD || $$name > $_[0]->{level};
return 1;
};

} ## end for my $name (qw( FATAL ERROR WARN INFO DEBUG TRACE ))

for my $name (
Expand Down Expand Up @@ -888,6 +897,20 @@ interface, but with lowercase method names:

logging functions, each emits a log at the corresponding level;

=item C<< is_trace >>

=item C<< is_debug >>

=item C<< is_info >>

=item C<< is_warn >>

=item C<< is_error >>

=item C<< is_fatal >>

log level test functions, each returns the status of the corresponding level;

=item C<< always >>

emit log whatever the configured logging level;
Expand Down
5 changes: 4 additions & 1 deletion t/04.object.t
Expand Up @@ -2,7 +2,7 @@
use strict;
use warnings;

use Test::More tests => 37; # last test to print
use Test::More tests => 73; # last test to print

#use Test::More 'no_plan';
use Log::Log4perl::Tiny qw( :levels );
Expand All @@ -23,15 +23,18 @@ for my $i (0 .. $#names) {

my $blocked = 1;
for my $name (@names) {
my $isfunc = 'is_'.$name;
$blocked = 0 if $name eq $current;
if ($blocked) {
log_is { $logger->$name("whatever $name") } '',
"minimum level $current, nothing at $name level";
is( $logger->$isfunc, 0, "is $name false");
}
else {
log_like { $logger->$name("whatever $name") }
qr/whatever\ $name/mxs,
"minimum level $current, something at $name level";
is( $logger->$isfunc, 1, "is $name true");
}
} ## end for my $name (@names)
} ## end for my $i (0 .. $#names)