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);
}