Hey Monks,
This is my first attempt in using log4perl and I seem to missing something very basic. My script performs a series of actions and I wanted to both log activites and send myself an email if anything major fails, like connecting to the database. I am successful at performing both, however I receive both $INFO and $FATAL messages to both my email and my log file, rather than just $FATAL to email and $INFO to my log file. I did not write this script in OO thus I believe the lack of heirarchy is causing my problem. I know I could use Log4perl qw(:easy), but based on my understanding (or lack there of) you can only send everything to STDOUT and STDERR. Thanks for any help. Here is my config file
log4perl.rootLogger=FATAL, A1, Mailer
log4perl.logger=INFO, log
log4perl.appender.A1=Log::Dispatch::File
log4perl.appender.A1.filename=test.log
log4perl.appender.A1.mode=append
log4perl.appender.A1.layout=PatternLayout
log4perl.appender.A1.layout.ConversionPattern=%d %p> %F{1}:%L %M - %m%
+n
log4perl.appender.Mailer = Log::Dispatch::Email::MailSendmail
log4perl.appender.Mailer.to = joeshmoe
log4perl.appender.Mailer.from = joeshmoe
log4perl.appender.Mailer.subject = Something's broken!
log4perl.appender.Mailer.layout = SimpleLayout
log4perl.appender.log=Log::Dispatch::File
log4perl.appender.log.filename=/mail.log
log4perl.appender.log.mode=append
log4perl.appender.log.layout=PatternLayout
log4perl.appender.log.layout.ConversionPattern=%d %p> %m%n
Here is a snip of code from my script
use Log::Log4perl;
Log::Log4perl->init("surv.conf"); #name of my config file
my $log = Log::Log4perl->get_logger();
$log->info("connecting to database");
my $dbh = DBI->connect(ORACLE_DATABASE_NAME, ORACLE_USER, ORACLE_PASSW
+ORD)
or die $log->fatal($DBI::errstr);
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.