Log::Log4perl config
March 14th, 2006 by RohanMan! I finally settled on a logging configuration for one of my upcoming projects. It uses the superb Log::Log4perl module.
After you get through your understanding of categories, levels and appenders, make sure you read the stuff about additivity and thresholds. I found the Log::Log4perl::FAQ indispensable.
Here is the config I used:
log4perl.category = ERROR, MAILER
log4perl.logger = DEBUG, LOGFILE
log4perl.logger.Google = DEBUG, LOGFILE
log4perl.logger.Google.Query = DEBUG, LOGFILE
log4perl.logger.Google.SOAP = DEBUG, LOGFILE
log4perl.logger.AWIS = DEBUG, LOGFILE
log4perl.logger.AWIS.UrlInfo = DEBUG, LOGFILE
log4perl.appender.LOGFILE = Log::Log4perl::Appender::File
log4perl.appender.LOGFILE.filename = /home/rohan/projects/saveoursearches/logs/system.log
log4perl.appender.LOGFILE.mode = append
log4perl.appender.LOGFILE.layout = PatternLayout
log4perl.appender.LOGFILE.layout.ConversionPattern = %d{ISO8601} %p %F{1} %M <%m>%n
log4perl.appender.MAILER = Log::Dispatch::Email::MailSend
log4perl.appender.MAILER.to = rohan
log4perl.appender.MAILER.subject = ALERT from saveoursearches.com
log4perl.appender.MAILER.buffered = 0
log4perl.appender.MAILER.layout = PatternLayout
log4perl.appender.MAILER.layout.ConversionPattern = %d{ISO8601} %p %F{1} %M <%m>%n
log4perl.appender.MAILER.Threshold = ERROR
log4perl.oneMessagePerAppender = 1
Each component in the system has a log level of DEBUG which I can change at a later stage. To prevent propagation of log messages up to the parent, I used log4perl.oneMessagePerAppender = 1, which the docs say is non-standard, but I’m fine with it. The root category for the level of ERROR uses the MAILER appender which has a threshold of ERROR. So only log messages with a level of ERROR and above (from all components in the system) are sent to my email address. They are logged to the file too.
