saberworks has asked for the wisdom of the Perl Monks concerning the following question:
I have been beating my head against this for a bit and I feel like I'm fundamentally misunderstanding how eval {} and $@ work. Given the following script with the following following log4perl configuration, I would expect that $@ wouldn't be unset in the middle of the if($@) block. What I'm seeing is that if I call any loglevel method on the $logger object it clears $@. Is this expected behavior?
yourlogger.conf:#!perl use warnings; use strict; use Log::Log4perl; Log::Log4perl->init_and_watch('yourlogger.conf', 10); my $logger = Log::Log4perl::get_logger('test_die'); $logger->warn("before eval"); eval { die 'foo'; }; if($@) { print $@; # I expect this to print "foo", it does $logger->debug('test'); print $@; # I expect this to print "foo", it doesn't! print 'after printing $@'; } print "\n";
What am I doing wrong?log4perl.rootLogger = DEBUG, stdout, file log4perl.appender.stdout = Log::Log4perl::Appender::Screen log4perl.appender.stdout.layout = Log::Log4perl::Layout::SimpleLayout log4perl.appender.stdout.stderr = 1 log4perl.appender.stdout.Threshold = DEBUG log4perl.appender.file = Log::Dispatch::FileRotate log4perl.appender.file.mode = append log4perl.appender.file.size = 10_000_000 log4perl.appender.file.max = 10 log4perl.appender.file.filename = foo.txt log4perl.appender.file.layout=PatternLayout log4perl.appender.file.layout.ConversionPattern=%H:%P (%c) %p - %d: {% +X{work}} %m%n
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Log4perl swallowing $@
by ikegami (Patriarch) on Oct 28, 2010 at 20:03 UTC | |
by saberworks (Curate) on Oct 28, 2010 at 20:31 UTC | |
by Urthas (Novice) on Oct 28, 2010 at 23:04 UTC | |
by Anonymous Monk on Oct 29, 2010 at 06:49 UTC | |
by andal (Hermit) on Oct 29, 2010 at 09:23 UTC | |
Re: Log4perl swallowing $@
by ELISHEVA (Prior) on Oct 29, 2010 at 02:34 UTC | |
Re: Log4perl swallowing $@
by saintmike (Vicar) on Dec 26, 2011 at 04:38 UTC | |
Re: Log4perl swallowing $@
by Anonymous Monk on Oct 29, 2010 at 06:57 UTC |
Back to
Seekers of Perl Wisdom