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 ;
}
-
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.