Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Help implementing log4perl

by Andre_br (Pilgrim)
on Oct 01, 2005 at 18:50 UTC ( [id://496670]=perlquestion: print w/replies, xml ) Need Help??

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

Hello my code friends

I´m trying to set up log4perl for my scripts but I seem to be forgetting something, as nothing gets written on the log file (nor emailed to me). Here´s my log4perl.conf:

log4perl.logger=INFO, FatalFile, FatalMailer, InfoLog log4perl.filter.MatchFatal = Log::Log4perl::Filter::LevelMatch log4perl.filter.MatchFatal.LevelToMatch = FATAL log4perl.filter.MatchFatal.AcceptOnMatch = true log4perl.filter.MatchInfo = Log::Log4perl::Filter::LevelMatch log4perl.filter.MatchInfo.LevelToMatch = INFO log4perl.filter.MatchInfo.AcceptOnMatch = true log4perl.appender.FatalFile=Log::Dispatch::File log4perl.appender.FatalFile.filename=test.log log4perl.appender.FatalFile.mode=append log4perl.appender.FatalFile.layout=PatternLayout log4perl.appender.FatalFile.layout.ConversionPattern=%d %p> %F{1}:%L % +M - %m%n log4perl.appender.FatalFile.Filter = MatchFatal log4perl.appender.FatalMailer = Log::Dispatch::Email::MailSend +mail log4perl.appender.FatalMailer.to = webmaster@mysite.com log4perl.appender.FatalMailer.from = log4perl log4perl.appender.FatalMailer.subject = Something's broken! log4perl.appender.FatalMailer.layout = SimpleLayout log4perl.appender.FatalMailer.Filter = MatchFatal log4perl.appender.InfoLog=Log::Dispatch::File log4perl.appender.InfoLog.filename=mailer.log log4perl.appender.InfoLog.mode=append log4perl.appender.InfoLog.layout=PatternLayout log4perl.appender.InfoLog.layout.ConversionPattern=%d %p> %m%n log4perl.appender.InfoLog.Filter = MatchInfo
And here´s the code supposed to be included at the beginning of my scripts:
use Log::Log4perl; Log::Log4perl->init("/home/mysite/log4perl/log4perl.conf");
The test script runs ok, without any complaint after loading the log4perl config call, but, as I said, nothing makes it to the error logs or to my email.

I need thy help

Thanks a lot!

Replies are listed 'Best First'.
Re: Help implementing log4perl
by izut (Chaplain) on Oct 01, 2005 at 19:48 UTC

    It helps if you post your code to us see what's going on. I hope you have instantiated a logger in your code like this:

    my $log = Log::Log4perl->get_logger('My::Application'); $log->info("Some message");

    If you didn't, remember Log::Log4perl can't do magic for you ;)


    Igor S. Lopes - izut
    surrender to perl. your code, your rules.
Re: Help implementing log4perl
by johnnywang (Priest) on Oct 01, 2005 at 21:34 UTC
    I use log4perl in most of my scripts, have to admit I've never used the filters. Does it work for you if you remove all the filters, and simply log everything together? i.e., something like:
    log4perl.logger=INFO, FatalFile, FatalMailer, InfoLog log4perl.appender.FatalFile=Log::Dispatch::File log4perl.appender.FatalFile.filename=test.log log4perl.appender.FatalFile.mode=append log4perl.appender.FatalFile.layout=PatternLayout log4perl.appender.FatalFile.layout.ConversionPattern=%d %p %F{1}:%L %M + - %m%n log4perl.appender.FatalMailer = Log::Dispatch::Email::MailSend +mail log4perl.appender.FatalMailer.to = webmaster@mysite.com log4perl.appender.FatalMailer.from = log4perl log4perl.appender.FatalMailer.subject = Something's broken! log4perl.appender.FatalMailer.layout = SimpleLayout log4perl.appender.InfoLog=Log::Dispatch::File log4perl.appender.InfoLog.filename=mailer.log log4perl.appender.InfoLog.mode=append log4perl.appender.InfoLog.layout=PatternLayout log4perl.appender.InfoLog.layout.ConversionPattern=%d %p %m%n
Re: Help implementing log4perl
by saintmike (Vicar) on Oct 02, 2005 at 18:26 UTC
    You might want to change the email address from webmaster@mysite.com to your own. Then try this:

    use Log::Log4perl; Log::Log4perl->init("log4perl.conf"); my $logger = get_logger("Foo::Bar"); $logger->info("this one's for mailer.log"); $logger->fatal("this one's for test.log and email");
    You will get
    • "this one's for mailer.log" in mailer.log
    • "this one's for test.log and email" in test.log
    • "this one's for test.log and email" in an email sent to you.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2024-04-20 05:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found