Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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?
#!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";
yourlogger.conf:
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
What am I doing wrong?

In reply to Log4perl swallowing $@ by saberworks

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-19 21:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found