log4perl multiple configs in a single conf file

356 Views Asked by At

Can i have multiple configurations specified in a single conf file?

i have specified something like this

log4perl.category.xml_script                = DEBUG, LOGFILE_XML_SCRIPT
log4perl.category.xml_script.XML_script_lib = DEBUG, LOGFILE_SCRIPT_LIB
log4perl.category.addrdec2xml               = DEBUG, LOGFILE_ADDRDEC2XML
log4perl.oneMessagePerAppender              = 1

xml_script and addrdec2xml are 2 independent scripts.

log4perl.appender.LOGFILE_XML_SCRIPT                           = Log::Log4perl::Appender::File
log4perl.appender.LOGFILE_XML_SCRIPT.filename                  = xml_script.log
log4perl.appender.LOGFILE_XML_SCRIPT.mode                      = overwrite
log4perl.appender.LOGFILE_XML_SCRIPT.layout                    = Log::Log4perl::Layout::PatternLayout
log4perl.appender.LOGFILE_XML_SCRIPT.layout.ConversionPattern  = %p %F(%L): [%c] %m%n

log4perl.appender.LOGFILE_SCRIPT_LIB                           = Log::Log4perl::Appender::File
log4perl.appender.LOGFILE_SCRIPT_LIB.filename                  = xml_script_lib.log
log4perl.appender.LOGFILE_SCRIPT_LIB.mode                      = overwrite
log4perl.appender.LOGFILE_SCRIPT_LIB.layout                    = Log::Log4perl::Layout::PatternLayout
log4perl.appender.LOGFILE_SCRIPT_LIB.layout.ConversionPattern  = %p %F(%L): [%c] %m%n

log4perl.appender.LOGFILE_ADDRDEC2XML                          = Log::Log4perl::Appender::File
log4perl.appender.LOGFILE_ADDRDEC2XML.filename                 = addrdec2xml.log
log4perl.appender.LOGFILE_ADDRDEC2XML.mode                     = overwrite
log4perl.appender.LOGFILE_ADDRDEC2XML.layout                   = Log::Log4perl::Layout::PatternLayout
log4perl.appender.LOGFILE_ADDRDEC2XML.layout.ConversionPattern = %p %F(%L): [%c]%n%m%n

When i run the scripts independently the other log file get cleaned. :( Any suggestions appreciated. I dont want to have multiple conf, so please suggest solution with a single conf file.

1

There are 1 best solutions below

3
On

Change the mode to append and make sure you are going to invoke the logger like this:

my $logger = get_logger('xml_script');

my $logger = get_logger('addrdec2xml');