Skip Menu |

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

Report information
The Basics
Id: 106473
Status: resolved
Priority: 0/
Queue: Log-Log4perl

People
Owner: Nobody in particular
Requestors: justice__8 [...] hotmail.com
Cc:
AdminCc:

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



Subject: OFF/ALL levels are inverted
Date: Sat, 15 Aug 2015 18:26:03 +0200
To: "bug-Log-Log4perl [...] rt.cpan.org" <bug-log-log4perl [...] rt.cpan.org>
From: JusTiCe 8 <justice__8 [...] hotmail.com>
In both L4P 1.44 (from a Debian testing) and 1.46 (downloaded from the CPAN), the following code: # ALL set to 0, OFF to 2^31 - 1 # it may be the opposite ! # comment in module: # log4j, for whatever reason, puts 0 as all and MAXINT as OFF. # this seems less optimal, as more logging would imply a higher # level. But oh well. Probably some brokenness that has persisted. :) # OFF is "no log/never log" I guess whereas ALL is "always log this statement whatever log level defined" use strict; use warnings; use Log::Log4perl; use Log::Log4perl::Level; my $l4pconf = { 'log4perl.category.l4pissue' => 'WARN, LOGFILE', 'log4perl.appender.LOGFILE' => 'Log::Log4perl::Appender::File', 'log4perl.appender.LOGFILE.filename' => 'l4plevelissue.log', 'log4perl.appender.LOGFILE.mode' => 'write', 'log4perl.appender.LOGFILE.layout' => 'Log::Log4perl::Layout::PatternLayout', 'log4perl.appender.LOGFILE.layout.ConversionPattern' => '%d %p> %F{1}:%L %M - %m %n', }; eval { Log::Log4perl->init_once ($l4pconf); $Log::Log4perl::caller_depth++; }; if ($@) { print STDERR "Log4Perl init error: $@\n"; } my $logger = Log::Log4perl->get_logger('l4pissue'); print "log some messages...\n"; $logger->log ($DEBUG, "a debug message"); $logger->log ($INFO, "a info message"); $logger->log ($WARN, "a warn message"); $logger->log ($ERROR, "a error message"); $logger->log ($FATAL, "a fatal message"); print "log an OFF msg\n"; $logger->log ($OFF, "a OFF message, SHOULD NOT BE THERE"); # should not be logged, but it is ! print "log an ALL msg\n"; $logger->log ($ALL, "a ALL message, SHOULD BE ALWAYS THERE"); # should be logged but it's not ! exit 0; produce log file: 2015/08/15 18:19:28 WARN> [undef]:[undef] main:: - a warn message 2015/08/15 18:19:28 ERROR> [undef]:[undef] main:: - a error message 2015/08/15 18:19:28 FATAL> [undef]:[undef] main:: - a fatal message 2015/08/15 18:19:28 OFF> [undef]:[undef] main:: - a OFF message, SHOULD NOT BE THERE expected behaviour: 2015/08/15 18:19:28 WARN> [undef]:[undef] main:: - a warn message 2015/08/15 18:19:28 ERROR> [undef]:[undef] main:: - a error message 2015/08/15 18:19:28 FATAL> [undef]:[undef] main:: - a fatal message 2015/08/15 18:19:28 ALL> [undef]:[undef] main:: - a ALL message, SHOULD BE ALWAYS THERE
I can see how this is confusing, however, the levels are defined in terms of thresholds for loggers that either let a message with a certain priority pass or block it. A logger with a threshold of ALL will allow all messages regardless of their priority. A logger with a threshold of OFF will allow no messages, except those with a priority of "OFF". It's counter-intuitive, but a message with priority OFF will not be blocked ever. To somehow make this more easily accessible, :easy mode defines use Log::Log4perl qw(:easy); ALWAYS "always makes it through"; which under the covers uses the OFF priority for the message. To address your second example: A logger with threshold ALL will let all messages pass, including messages with priority ALL. A logger with a threshold less than ALL (e.g. WARN), however, will block a message with priority ALL. Hope this clarifies this admittedly confusing behavior.