Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Change email config for Log::Dispatch::Email::MailSender

by tonytronics (Initiate)
on May 05, 2015 at 19:20 UTC ( [id://1125760]=perlquestion: print w/replies, xml ) Need Help??

tonytronics has asked for the wisdom of the Perl Monks concerning the following question:

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

Replies are listed 'Best First'.
Re: Change email config for Log::Dispatch::Email::MailSender
by Anonymous Monk on May 05, 2015 at 22:17 UTC
    Can you explain what this liine does, esp the qw part?  use Log::Log4perl qw(get_logger :levels);

      Have you tried reading the Log::Log4perl documentation? The qw operator is documented in perlop: qw. Importing from modules is documented in perlfunc: use.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

        Have you tried reading the Log::Log4perl documentation? The qw operator is documented in perlop: qw. Importing from modules is documented in perlfunc: use.

        Hi afoken, I am not the OP, I was trying to engage the OP and inspire a lightbulb moment ... works better when the OP is around :)

        Anyway, changing configuration at runtime is not how you're supposed to work it :)

        use Log::Log4perl qw/ get_logger /; ... get_logger("Winmail")->info("yay!"); ... get_logger("Failmail")->info("boo!"); ... get_logger("Bobmail")->info("get to work!");

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1125760]
Approved by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2024-04-25 08:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found