Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??


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.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/ line 58 during global destruction.

Without buffering its  Died at site/lib/Mail/ 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/ line 158 during global destruction.

as without buffering  No such file or directory at site/lib/Mail/ 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

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

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (3)
    As of 2020-12-01 05:25 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found