From: Martin J. E. <mar...@ea...> - 2011-11-21 09:23:40
|
On 21/11/11 04:46, Mike Schilli wrote: > On Tue, 1 Nov 2011, Martin J. Evans wrote: > >> So substituting warn with logwarn does not always warn! > > That's an interesting case. The way it's implemented right now is that > logwarn() will only call warn() (along with other log4perl actions) if > the log level is greater or equal than WARN. > > logdie(), on the other hand, will call die() unconditionally, because > it's an action, not only a message. > > -- -- Mike So simply substituting warn with logwarn can change the way your program works. It is not for me to tell you how Log::Log4perl should work but I find this behaviour unacceptable as my program will behave differently depending on the log level. Logging should be logging, not changing the way my program runs. Example: $ perl -le '$SIG{__WARN__} = sub {CORE::die "Warning:\n", @_, "\n"}; use Log::Log4perl qw(get_logger); my $lh = get_logger("BET::Data::Remove");warn("fred"); print "ok";' Warning: fred at -e line 1. Change the warn to logwarn: $ perl -le '$SIG{__WARN__} = sub {CORE::die "Warning:\n", @_, "\n"}; use Log::Log4perl qw(get_logger); my $lh = get_logger("BET::Data::Remove");$lh->logwarn("fred"); print "ok"; ok Would you consider changing this? If not, I would be most grateful if you could you point me at the place where I could change this behaviour or tell my how I could override it. Martin >> Hi, >> >> Is this really the intended behaviour: >> >> perl -w -le 'use strict;use warnings;use Log::Log4perl qw(get_logger); my $lh = get_logger("BET::Data::Remove"); $lh->debug("fred");$lh->logwarn("warning from l:l"); warn("warning");' >> >> Log4perl: Seems like no initialization happened. Forgot to call init()? >> warning at -e line 1. >> >> i.e., if something does not call init for Log::Log4perl but has a log handle when logwarn is called a warn does not happen? >> > >> >> I spent some time debugging a problem this morning only to discover this. I find this most worrying as I'd expect the warn to happen whatever. If you substitute logdie for die it seems to work. >> >> perl -MLog::Log4perl -le 'print $Log::Log4perl::VERSION;' >> 1.33 >> This is perl, v5.10.1 (*) built for i686-linux-gnu-thread-multi >> >> Martin >> -- Martin J. Evans Easysoft Limited http://www.easysoft.com |