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

Re: Possible scoping issue with Log::Log4perl logger

by choroba (Archbishop)
on Jun 15, 2018 at 22:01 UTC ( #1216753=note: print w/replies, xml ) Need Help??


in reply to Possible scoping issue with Log::Log4perl logger

You don't show how the e-mail gets send. Note that global destruction (happening on program end) doesn't guarantee the order in which the objects are destroyed - maybe some information needed to send the e-mail is already missing?

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: Possible scoping issue with Log::Log4perl logger
by talexb (Canon) on Jun 15, 2018 at 22:18 UTC

    Sorry -- I assume that this was pretty straightforward. here's the configuration file, edited for security ..

    1 # Configuration file for work script 2 3 log4perl.logger = INFO, Screen, Logfile, Mailer 4 5 log4perl.appender.Screen = Log::Log4perl::Appender::Scree +n 6 log4perl.appender.Screen.stderr = 0 7 log4perl.appender.Screen.layout = Log::Log4perl::Layout::Pattern +Layout 8 log4perl.appender.Screen.layout.ConversionPattern = %d %p : %m%n 9 log4perl.appender.Screen.Threshold = INFO 10 11 log4perl.appender.Logfile = Log::Log4perl::Appender::File 12 log4perl.appender.Logfile.filename = work_script.log 13 log4perl.appender.Logfile.mode = append 14 log4perl.appender.Logfile.layout = Log::Log4perl::Layout::Patter +nLayout 15 log4perl.appender.Logfile.layout.ConversionPattern = %d %p : %m%n 16 17 log4perl.appender.Mailer = XYZ::LogDispatchEmailSender 18 log4perl.appender.Mailer.to = someguy@example.com 19 # 20 log4perl.appender.Mailer.subject = XYZ Topic 21 log4perl.appender.Mailer.layout = Log::Log4perl::Layout::PatternL +ayout 22 log4perl.appender.Mailer.layout.ConversionPattern = %d %p : %m%n 23 log4perl.appender.Mailer.Threshold = INFO
    The module I use to actually send an E-Mail is here:
    1 package XYZ::LogDispatchEmailSender; 2 3 # 2018-0515: From the MetaCPAN page 4 # https://metacpan.org/pod/Log::Dispatch::Email, here's a local m +odule that 5 # will send E-Mail. .. 6 # .. 7 8 use Log::Dispatch::Email; 9 10 use base qw( Log::Dispatch::Email ); 11 12 use Email::Simple; 13 use Email::Sender::Simple qw(sendmail); 14 use Email::Sender::Transport::SMTP qw(); 15 use Try::Tiny; 16 17 use lib ..; 18 19 use XYZEMail; 20 21 sub send_email 22 { 23 my $self = shift; 24 my %p = @_; 25 26 my $message = Email::Simple->create( 27 header => [ 28 To => join(', ',@{ $self->{'to'} }), 29 From => 'anotherguy@example.com', 30 Subject => $self->{'subject'}, 31 ], 32 body => $p{ message }, 33 ); 34 35 try { 36 sendmail( 37 $message, 38 { 39 from => 'anotherguy@example.com', 40 transport => Email::Sender::Transport::SMTP->new( 41 { 42 host => $XYZEMail::Host, 43 port => $XYZEMail::Port, 44 sasl_username => $XYZEMail::User, 45 sasl_password => $XYZEMail::Password, 46 ssl => 'starttls', 47 } 48 ) 49 } 50 ); 51 } 52 catch { 53 warn "sending failed: $_"; 54 }; 55 } 56 57 1;

    Alex / talexb / Toronto

    Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1216753]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2020-12-01 06:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?