I'm seeing behavior that I can't explain when using log4perl to send a message by email.
So the following test script works just fine and an email is sent without problems:
#!/usr/bin/perl use strict; use warnings; use Log::Log4perl qw(:easy); use Log::Dispatch; my $appender_email = Log::Log4perl::Appender->new( "Log::Dispatch::Email::SSMTP", threshold => "INFO", to => 'myemail@mail.com', subject => 'Perl script message' ); my $email_logger = get_logger(); $email_logger->level($INFO); $email_logger->add_appender($appender_email); $email_logger->info('hi');
The "Log::Dispatch::Email::SSMTP" is a module I wrote to send emails using the ssmtp command.
The weirdness begins when this same exact code is moved to another package in another file in the same directory as my original script. When I do that and use that package from within my original script, no email gets sent and there are no errors thrown.
However, if I change:
Log::Dispatch::Email::SSMTP
to
Log::Log4perl::Appender::Screen
It prints out "hi" to the screen just fine when I run my script.
So if log4perl works when sending the message to the screen, why doesn't it work when trying to send an email? And why does the same code fire an email from within the original script and not from a package? Again, there are no errors getting thrown or any kind of indication that something went wrong.
$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon";
$nysus = $PM . $MCF;
Click here if you love Perl Monks
In reply to log4perl run from within another package not firing messages sent through email by nysus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |