in reply to Possible scoping issue with Log::Log4perl logger
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 ; }