[tpm] Log::Log4perl with multiple files

Ilia samogon at gmail.com
Wed Feb 4 15:38:51 PST 2009


Currently I use Log::Log4perl to log all debug/warn/info/error
messages to a single file. I'd like to use l4p to log to separate
files. The filename should be determined based on the category I pass
to Log::Log4perl->get_logger.

>From the docs it seems I would have to manually setup l4p categories
in the configuration file.
ie.:
    log4perl.category.Bar.Twix         = DEBUG, TwixLogfile
    log4perl.appender.TwixLogfile          = Log::Log4perl::Appender::File
    log4perl.appender.TwixLogfile.filename = twix.log
    log4perl.category.Bar.Mars         = WARN, MarsLogfile
    log4perl.appender.MarsLogfile          = Log::Log4perl::Appender::File
    log4perl.appender.MarsLogfile.filename = mars.log

But I don't want to setup a hundred different categories.

So what I'm looking for is a custom Appender that enables syntax such as:
  log4perl.rootLogger=DEBUG, LOGFILE
  log4perl.appender.LOGFILE=Log::Log4perl::Appender::AutoFile
  log4perl.appender.LOGFILE.container=logs

Log::Log4perl::Appender::AutoFile would automatically write to a log
file in the "logs" directory.

eg. Log::Log4perl->get_logger('Bar::Twix') would log to logs/bar.twix.log

Does someone have experience with Log::Log4perl in this capacity? Is
there another module I should look into?

I found a similar request on the log4perl-devel mailing list but it
goes back to 2007
http://www.mail-archive.com/log4perl-devel@lists.sourceforge.net/msg00084.html

ilia.


More information about the toronto-pm mailing list