Log4perl: Category Logging at a Different Level than Root

(This is probably intuitively obvious to everyone else...)

Here is a sample Log::Log4perl configuration where the root logs at WARN, package 'Joe' logs at 'INFO', and package 'Zoe::Marie' logs at ERROR:

log4perl.rootLogger=WARN, LOGFILE log4perl.logger.Joe=INFO, LOGFILE log4perl.logger.Zoe.Marie=ERROR, LOGFILE

log4perl.additivity.Joe = 0
log4perl.additivity.Zoe.Marie = 0

log4perl.appender.LOGFILE=Log::Log4perl::Appender::File
log4perl.appender.LOGFILE.filename=/tmp/test-Log4perl.log
log4perl.appender.LOGFILE.mode=append

log4perl.appender.LOGFILE.layout=PatternLayout
log4perl.appender.LOGFILE.layout.ConversionPattern=[%r] %F %L %c - %m%n

Because of how Log::Log4perl was built, you don't need to do anything special in your code to support this multi-level priority logging -- each package can just use Log::Log4perl->get_logger() to get the the logging object and it all falls out in the wash.

(In theory, this type of configuration should work for Log4j and Log4net also.)

1 Comment

Leave a comment

About Mark Leighton Fisher

user-pic Perl/CPAN user since 1992.