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

I fear I have a question answered easily so I must demonstrate that I have done the proper work before coming here for help. I have searched PM's database of questions for log4perl (went down 3 pages). I've googled the question and read tutorials here and here. I've also asked 2 colleages (although they were basing their answers off of log4j). This is my first brushes with log4j or log4perl.

If I have a rootLogger defined for priority of ERROR, and then another logger (let's call logger a) defined for priority of INFO, am I correct in thinking that a call to logger a with a message of priority INFO will trigger only logger a's appenders and not rootLogger because rootLogger has a priority of ERROR? Because if so, that's certainly not the case. Please help explain this to me!

The conf file
############Root############ log4perl.rootLogger=ERROR, A1 log4perl.appender.A1=Log::Log4perl::Appender::File log4perl.appender.A1.filename=error.log log4perl.appender.A1.mode=write log4perl.appender.A1.layout=PatternLayout log4perl.appender.A1.layout.ConversionPattern=[%d{ABSOLUTE}] %p %c - % +m%n ############File only ############# log4perl.logger.fileLogger=INFO, LOGFILE log4perl.appender.LOGFILE=Log::Log4perl::Appender::File log4perl.appender.LOGFILE.filename=log.log log4perl.appender.LOGFILE.mode=write log4perl.appender.LOGFILE.layout=PatternLayout log4perl.appender.LOGFILE.layout.ConversionPattern=[%d{ABSOLUTE}] %p % +c - %m%n
The perl code
use warnings; use strict; use Log::Log4perl qw(get_logger); Log::Log4perl->init("log.conf"); my $log = get_logger("fileLogger"); $log->debug("Log only Debug message"); $log->info("Log only Info message"); $log->error("Log only Error message"); $log->logwarn("Log only We have hit a warning\n");
output of log.log
[system]$ cat log.log [14:06:36,001] INFO fileLogger - Log only Info message [14:06:36,001] ERROR fileLogger - Log only Error message [14:06:36,002] WARN fileLogger - Log only We have hit a warning
Output of error.log - and here is where the output is unexpected
[system]$ cat error.log [14:06:36,001] INFO fileLogger - Log only Info message [14:06:36,001] ERROR fileLogger - Log only Error message [14:06:36,002] WARN fileLogger - Log only We have hit a warning


Lastly I read that "categories are also called "Loggers" in Log4perl, both refer to the the same thing and these terms are used interchangeably". Does this mean log4perl.logger.fileLogger and log4perl.category.fileLogger are the same thing?

Replies are listed 'Best First'.
Re: log4perl inheritance
by daviddd (Acolyte) on Apr 20, 2011 at 20:35 UTC

    I believe what you are seeing is addressed in the section of the Log::Log4perl FAQ entitled "I keep getting duplicate log messages! What's wrong?"

    perldoc Log::Log4perl::FAQ
      Thank you for pointing out what I missed. This answers my question completely.