Greetings Elders

I have switched my loggin to use Log::Log4perl and Im having a hard time using Log::Dispatch::Email::MailSender for emailing logs. The code snippet below is my working example.

use Log::Log4perl qw(get_logger :levels); my $log4perl_conf=<<CFG log4perl.rootLogger=INFO, Email log4perl.appender.Email=Log::Dispatch::Email::MailSender log4perl.appender.Email.to=me\@me.com log4perl.appender.Email.from=me\@me.com log4perl.appender.Email.smtp=smtp.me.com log4perl.appender.Email.min_level=info log4perl.appender.Email.layout=Log::Log4perl::Layout::PatternLayout log4perl.appender.Email.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:s +s} [%F{1}:%c{1}] %5p> %m%n CFG ; Log::Log4perl::init(\$log4perl_conf); my $logger = Log::Log4perl->get_logger(); $logger->info('The first message bla bla'); $logger->info('The second message bla bla'); some_func(); sub some_func { my $logger = Log::Log4perl->get_logger(); $logger->info("some_func was called"); }

Here are my questions

  1. why does the logger not send emails unless I add get a logger locally by adding my $logger = Log::Log4perl->get_logger(); to some_func Im not sure why it cant use the global version
  2. How do I get access to the logger configuration so I can change the email subject during execution say to indicate success or failure. I basically want to change things like subject or to address dynamically in my script

As a workaround for Q2 above in my main program I now use Log::Log4perl::Appender::String to store the message and then ues send an email at the end of my script using MIME::Lite. I would prefer to have this all handled by the logger. Thanks


In reply to Change email config for Log::Dispatch::Email::MailSender by tonytronics

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.