Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Implementing Log::Log4perl

by horrendo (Sexton)
on Aug 10, 2008 at 23:56 UTC ( #703501=perlquestion: print w/replies, xml ) Need Help??
horrendo has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I am looking at replacing our existing logging mechanism with Log::Log4perl.

The current mechanism is very simple. We have a base class that all classes inherit from. That class defines 2 methods - ->feedback and ->notify. The ->feedback method outputs to stdout and ->notify outputs to stderr.

I was hoping to set up Log4perl with a default initialisation file to mimic the current functionality (for backward compatibility) while allowing projects to take advantage of the power of Log4perl at their leisure.

Here is my initial stab at a config file ...

log4perl.rootLogger=DEBUG, LogFile, StdErr, StdOut log4perl.appender.LogFile=Log::Dispatch::File log4perl.appender.LogFile.filename=/project/xxx/log/plx.log log4perl.appender.LogFile.mode=append log4perl.appender.LogFile.min_level=error log4perl.appender.LogFile.layout=PatternLayout log4perl.appender.LogFile.layout.ConversionPattern=%-5p[%P]%d{yyyyMMdd + HH:mm:ss.SSSSSS} %m [%F line %L]%n log4perl.appender.StdErr=Log::Dispatch::Screen log4perl.appender.StdErr.stderr=1 log4perl.appender.StdErr.min_level=error log4perl.appender.StdErr.layout=PatternLayout log4perl.appender.StdErr.layout.ConversionPattern=[%P]%d{yyyyMMdd HH:m +m:ss.SSSSSS} %m%n log4perl.appender.StdOut=Log::Dispatch::Screen log4perl.appender.StdOut.stderr=0 log4perl.appender.StdOut.min_level=debug log4perl.appender.StdOut.max_level=warning log4perl.appender.StdOut.layout=PatternLayout log4perl.appender.StdOut.layout.ConversionPattern=[%P]%d{yyyyMMdd HH:m +m:ss.SSSSSS} %m%n
The question I have is to do with Log4perl levels and their corresponding Log::Dispatch levels. From what I can see, the 'lowest' level for Log::Dispatch is 'warning', whereas the lowest level for Log4perl is trace. Using the above config file, I was hoping to have anything output via ->warn, ->debug, ->info, or ->trace to be output to stdout. I can't seem to get ->trace messages to appear on stdout.

Any clues (or comments on my implementation)?


Replies are listed 'Best First'.
Re: Implementing Log::Log4perl
by tilly (Archbishop) on Aug 11, 2008 at 03:18 UTC
    It is a little confusing, but what you have to do is change the rootLogger from DEBUG to TRACE, then get rid of the line log4perl.appender.StdOut.min_level=debug and it will work.
      D'oh. I should have seen that.

      Thanks very much !!

Re: Implementing Log::Log4perl
by saintmike (Vicar) on Aug 13, 2008 at 00:56 UTC