http://qs321.pair.com?node_id=1216779


in reply to Possible scoping issue with Log::Log4perl logger

I've poked the Log::log4perl internals a bit before, but I don't have any of it memorized so this is mostly guesses but:

Anyway, my workaround is going to be to call get_logger in whichever scope I need to do logging.

Right, this is what you have to do here. Sounds like you understand why.

but I'm left wondering why doesn't Log::Log4perl see that the logger has gone out of scope in the work script and send the E-Mail?

For the same reason you can call ->get_logger without specifying the config again and get the expected logger object. Even though its went out of scope in your block, the instance of your logging object still exists in log4perl, so its not went out of scope everywhere yet. If you read through the l4p FAQ and review the email and buffering parts, it might might help explain whats going on? #How-can-I-configure-Log::Log4perl-to-send-me-email-if-something-happens?

Replies are listed 'Best First'.
Re^2: Possible scoping issue with Log::Log4perl logger
by talexb (Chancellor) on Jun 16, 2018 at 16:37 UTC

    Thanks for the link to the documentation .. I guess I'm being thick, but it strikes me that the script ending would mean that the logger goes out of scope .. which should send the E-Mail.

    But I'm going to have to do some testing on that aspect of things. Appreciate the feedback. :)

    Alex / talexb / Toronto

    Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.