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

Hi All, I am trying to use log4perl to send alert emails from my script... I'm not being successful. Here is the code I have for setting up an email logger for perl using Log::Dispatch::Email::MailSendmail:
use Log::Log4perl qw(get_logger :levels); my $log4perl_conf=<<CFG log4perl.rootLogger=INFO, Email log4perl.appender.Email=Log::Dispatch::Email::MailSendmail log4perl.appender.Email.to=me@company.com log4perl.appender.Email.from=me@company.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('Something bad is happening');
I'm not getting a delivered email. However, I know the base Mail::SendMail module delivers an email:
use Mail::Sendmail; # TLRTSRMG-CapacityPlanning@thomson.com %mail = ( To => 'me@company.com', From => 'me@company.com', Message => "Sorry, testing this out for emailing -- please i +gnore", Subject => "DELETE ME: Email Testing" ); sendmail(%mail) or die $Mail::Sendmail::error; print "OK. Log says:\n", $Mail::Sendmail::log;
Any ideas how to get the log4perl appender working? Thanks, Matt

Replies are listed 'Best First'.
Re: log4perl and Log::Dispatch::Email::MailSendmail
by pilcrow (Sexton) on Oct 09, 2007 at 01:41 UTC

    As posted, your CFG here-doc interpolates a variable named @company, which, if the case, is probably Not What You Want (tm).

    -pilcrow
      (hits head with palm) thanks -- i didn't do due diligence and inspect the string i was sending as configuration... copy and pasted that out of a Config::IniFiles .ini file that I use (that doesn't interpolate ) and wrapped it in a HERE document (which does). Thanks again -- I'll try it out tomorrow at work.