Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hi

I see things working as designed so far, as in the appender gets called

#!/usr/bin/perl -- use strict; use warnings; use Log::Log4perl 1.49; my $logger ; sub bye { $logger->info("bye"); } { my $logconfig = <<'__LOGCONFIG__'; log4perl.rootLogger = ALL, First, Mailer log4perl.appender.First = Log::Log4perl::Appender::Screen log4perl.appender.First.layout = SimpleLayout log4perl.appender.Mailer = FakeMailSend log4perl.appender.Mailer.to = FakeMailSend@example.com log4perl.appender.Mailer.subject = FakeMailSend log4perl.appender.Mailer.layout = SimpleLayout # log4perl.appender.Mailer.buffered = 0 __LOGCONFIG__ Log::Log4perl::init( \$logconfig ); $logger = Log::Log4perl->get_logger; $logger->debug('debug'); $logger->info('info'); $logger->warn('warn'); $logger->error('error'); $logger->trace('trace'); $logger->fatal('fatal'); bye; } exit( 0 ); BEGIN { package FakeMailSend; use Log::Dispatch::Email::MailSend qw[]; use base qw( Log::Dispatch::Email::MailSend ); sub send_email { warn "@_\n"; } 1; } __END__ DEBUG - debug INFO - info WARN - warn ERROR - error TRACE - trace FATAL - fatal INFO - bye FakeMailSend=HASH(0xe33e14) message DEBUG - debug INFO - info WARN - warn ERROR - error TRACE - trace FATAL - fatal INFO - bye

But if I actually try sending the mail (rename my sub send_mail)

Can't locate object method "open" via package "Mail::Mailer::smtp" at +lib/Mail/Send.pm line 58 during global destruction.

Without buffering its  Died at site/lib/Mail/Mailer.pm line 158. for every attempt.

An explicit  undef $logger ; produces the same good result

Adding  use Mail::Mailer::smtp(); produces the same failure to send the mail to example :)  No such file or directory at site/lib/Mail/Mailer.pm line 158 during global destruction.

as without buffering  No such file or directory at site/lib/Mail/Mailer.pm line 158.

Trying to  require Mail::Mailer::smtp; from within send_email fails as before  Can't locate object method "open" via package "Mail::Mailer::smtp"

So, Mail::Mailer::smtp can't be loaded during global destruction. Does Email::... eventually use it? Not important :)

So, if using a global for convenience, solution is

END { undef $logger ; }

In reply to Re: Possible scoping issue with Log::Log4perl logger ( END { undef $log; } ) by beech
in thread Possible scoping issue with Log::Log4perl logger by talexb

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 studying the Monastery: (2)
As of 2024-05-29 04:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found