Pmarcoen
Pmarcoen

Reputation: 1236

log4perl: logcluck keeps being displayed

I am experimenting with log4perl and came upon a curious problem :

I configure my log4perl to log everything above DEBUG level, I want to output everything to a file, however, I only want to display errors or fatals to the screen. So this is my config file :

#############################################################################################################################
## Logger                                                                                                                  ##
#############################################################################################################################
log4perl.logger                                     = DEBUG, fileLog, screenLog

#############################################################################################################################
## File Log (all levels)                                                                                                   ##
#############################################################################################################################
log4perl.appender.fileLog                       = Log::Log4perl::Appender::File
log4perl.appender.fileLog.filename              = error_log
log4perl.appender.fileLog.mode                  = append
log4perl.appender.fileLog.layout                = Log::Log4perl::Layout::PatternLayout
log4perl.appender.fileLog.layout.ConversionPattern = %d [%p] [%F line %L] %m%n

#############################################################################################################################   
## Screen Log (only error level or higher)                                                                                 ##
#############################################################################################################################
log4perl.appender.screenLog                       = Log::Log4perl::Appender::Screen
log4perl.appender.screenLog.Threshold               = ERROR                                     
log4perl.appender.screenLog.layout                   = Log::Log4perl::Layout::PatternLayout
log4perl.appender.screenLog.layout.ConversionPattern = %d [%p] [%F line %L] %m%n

Notice the Threshold set to error for screen output ! This works great for regular $logger->error and $logger->warn commands, the errors get output to both file and screen, the warns only to the file.

However, when I try $logger->logcluck("cluck"), it still gets output to the screen even though cluck is on WARN level !

Curiously enough, if I set my file Threshold to ERROR it doesnt show up in my file AND if I set my overall level to ERROR it doesnt show up on screen either ..

Any ideas as to why this is happening ?

Upvotes: 3

Views: 246

Answers (1)

Tanktalus
Tanktalus

Reputation: 22274

It's because logcluck does both logging (as a warning) and clucking (Carp::cluck). And it's the latter that prints it to the console.

If you want the cluck to only appear in the log, I'm not sure there is an answer for that short of calling Carp::longmess yourself, and logging that.

Upvotes: 3

Related Questions