Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Log-Dispatch CPAN distribution.

Report information
The Basics
Id: 66615
Status: resolved
Priority: 0/
Queue: Log-Dispatch

People
Owner: Nobody in particular
Requestors: frioux [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 2.29



Subject: is_$level support
Enjoy a patch to add is_$foo support to Log::Dispatch
Subject: woo.patch
diff -r 8bfdfceff8e4 Changes --- a/Changes Mon Jan 24 00:43:12 2011 -0600 +++ b/Changes Mon Mar 14 19:44:33 2011 -0500 @@ -1,3 +1,6 @@ +- Add is_$level methods for compatibility with Log::Contextual (frew) + + 2.28 2010-12-13 - The Log::Dispatch module still had version 2.26 in the last diff -r 8bfdfceff8e4 lib/Log/Dispatch.pm --- a/lib/Log/Dispatch.pm Mon Jan 24 00:43:12 2011 -0600 +++ b/lib/Log/Dispatch.pm Mon Mar 14 19:44:33 2011 -0500 @@ -222,6 +222,19 @@ return 0; } +sub is_debug { shift->would_log('debug' ) } +sub is_info { shift->would_log('info' ) } +sub is_notice { shift->would_log('notice' ) } +sub is_warning { shift->would_log('warning' ) } +sub is_warn { shift->would_log('warn' ) } +sub is_error { shift->would_log('error' ) } +sub is_err { shift->would_log('err' ) } +sub is_critical { shift->would_log('critical' ) } +sub is_crit { shift->would_log('crit' ) } +sub is_alert { shift->would_log('alert' ) } +sub is_emerg { shift->would_log('emerg' ) } +sub is_emergency { shift->would_log('emergency' ) } + sub _require_dynamic { my ($class) = @_; @@ -419,6 +432,12 @@ Given a log level, returns true or false to indicate whether or not anything would be logged for that log level. +=item * is_C<$level> + +Basically a curried C<would_log>. To be clear, the following are equivalent: + + $logger->would_log('debug') == $logger->is_debug + =back =head2 Output objects diff -r 8bfdfceff8e4 t/01-basic.t --- a/t/01-basic.t Mon Jan 24 00:43:12 2011 -0600 +++ b/t/01-basic.t Mon Mar 14 19:44:33 2011 -0500 @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 165; +use Test::More tests => 167; use File::Spec; use File::Temp qw( tempdir ); @@ -691,9 +691,19 @@ ); ok( + !$dispatch->is_debug, + "will not log 'debug'" + ); + + ok( $dispatch->would_log('crit'), "will log 'crit'" ); + + ok( + $dispatch->is_crit, + "will log 'crit'" + ); } {