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

Title:
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, details, 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, summary, 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.