From: Mike S. <m...@pe...> - 2013-12-21 22:42:29
|
Hi Dave, you're defining different loggers, but what you really want is define different appenders attached to a single logger. A logger has a category ("" or "main" or "Foo::Bar"), which determines which package namespace to accept messages from, and a set of appenders which it forwards the message to after it determines it should be logged because it exceeds the required level threshold. Your :easy configuration defines two loggers with identical categories, which results in second logger clobbering the first one :). Unfortunately, Log4perl doesn't warn you if you do that in easy mode, had you used a configuration file to set up your configuration, Log4perl would have warned you: log4perl.category redefined at PropertyConfigurator.pm line 98. Now, unfortunately, there's no way to do what you want in easy mode, but you need to use a standard configuration file or string instead. The following snippet defines one logger, which has two appenders attached to it: use Log::Log4perl qw(:easy); Log::Log4perl->init( \<<EOT ); log4perl.logger = TRACE, Screen, File log4perl.appender.Screen = Log::Log4perl::Appender::Screen log4perl.appender.Screen.layout = SimpleLayout log4perl.appender.File = Log::Log4perl::Appender::File log4perl.appender.File.filename = test.log log4perl.appender.File.layout = SimpleLayout log4perl.appender.Screen.Threshold = INFO EOT INFO "Goes to screen and file"; TRACE "Only goes to file"; The logger's level is trace, so that it forwards all messages trace and above to both appenders, but the file appender blocks everything below INFO with its threshold setting. Hope that helps! -- -- Mike Mike Schilli m...@pe... On Wed, 18 Dec 2013, Dave Pointon wrote: > Hi gents , > > I think that I'm experiencing some unexpected behaviour when using > easy_init() with multiple logger definitions (as suggested in the > perldoc), viz ... the reporting level is apparently determined by the > last of the definitions c/w being individually applicable e.g. > > With the call > > Log::Log4perl->easy_init( > { > name => 'LOG', > file => ">$LOGGER_FNAME", > layout => $log_layout, > level => $TRACE, > }, > { > name => 'SCR', > file => 'STDOUT', > layout => $log_layout, > level => $INFO, > }, > ); > > both logs i.e. STDOUT and the file, contain only INFO and above > messages, whereas the call > > Log::Log4perl->easy_init( > { > name => 'SCR', > file => 'STDOUT', > layout => $log_layout, > level => $INFO, > }, > { > name => 'LOG', > file => ">$LOGGER_FNAME", > layout => $log_layout, > level => $TRACE, > }, > ); > > results in all messages being output to both logs. > > In both of the above cases, I expected messages of INFO and above to > STDOUT and all message to the log file, so the question is: Is this a > mis-understanding on my part, or is there an actual defect here ? > > TIA & best rgds , > > |