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: 106495
Status: resolved
Priority: 0/
Queue: Log-Dispatch

People
Owner: Nobody in particular
Requestors: kfm [...] plushkava.net
Cc:
AdminCc:

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



Subject: Numeric log levels do not function (contrary to documentation)
Date: Mon, 17 Aug 2015 20:35:12 +0100
To: bug-Log-Dispatch [...] rt.cpan.org
From: Kerin Millar <kfm [...] plushkava.net>
Hi, The documentation claims that levels may be specified numerically, where debug is 0 and emergency is 7. However, this does not appear to be the case. $ perl -MLog::Dispatch -E 'say $Log::Dispatch::VERSION; $log = Log::Dispatch->new(); $log->log(level => 0, message => "test")' 2.48 Logging level was not provided at -e line 1 A quick peek at level_is_valid() brings two issues to the fore. Firstly, 0 does not evalute as true, causing it to immediately croak. The second is that the %LEVELS hash only contains symbolic keys and, therefore, the sub will only ever return undef when given a numeric value. Support for numeric values would be very useful. On a related note, treating 0 as debug and 7 as emergency would be the inverse of how the constants in Sys::Syslog work. $ perl -MSys::Syslog=:macros -E 'say $_ for LOG_DEBUG, LOG_EMERG' 7 0 Assuming that this bug is resolved, I would recommend that the numbers be in line with the system constants. Otherwise, it is impossible to use these constants directly without horrid workarounds, such as this: sub syslog_priority { my $n = shift; if (! defined $n || $n !~ /^\d+\z/ || $n > 7 || $n < 0) { return undef; } return abs($n - 7); }
On Mon Aug 17 15:35:33 2015, kfm@plushkava.net wrote: Show quoted text
> Hi, > > The documentation claims that levels may be specified numerically, > where debug is 0 and emergency is 7. However, this does not appear to > be the case. > > $ perl -MLog::Dispatch -E 'say $Log::Dispatch::VERSION; $log = > Log::Dispatch->new(); $log->log(level => 0, message => "test")' > 2.48 > Logging level was not provided at -e line 1 > > A quick peek at level_is_valid() brings two issues to the fore. > Firstly, 0 does not evalute as true, causing it to immediately croak. > The second is that the %LEVELS hash only contains symbolic keys and, > therefore, the sub will only ever return undef when given a numeric > value. > > Support for numeric values would be very useful. On a related note, > treating 0 as debug and 7 as emergency would be the inverse of how the > constants in Sys::Syslog work. > > $ perl -MSys::Syslog=:macros -E 'say $_ for LOG_DEBUG, LOG_EMERG' > 7 > 0 > > Assuming that this bug is resolved, I would recommend that the numbers > be in line with the system constants. Otherwise, it is impossible to > use these constants directly without horrid workarounds, such as > this: > > sub syslog_priority { > my $n = shift; > if (! defined $n || $n !~ /^\d+\z/ || $n > 7 || $n < 0) { > return undef; > } > return abs($n - 7); > }
Internally there's a lot of code that already handles the level as a number, so I don't think reversing the sense of the numbers is going to happen. However, not accepting the levels as a number is probably a bug,
Show quoted text
> However, not accepting the levels as a number is probably a > bug,
PR https://github.com/houseabsolute/Log-Dispatch/pull/15 submitted.