From: Dave P. <dpo...@li...> - 2013-12-18 13:41:36
|
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 , -- Dave Pointon FIAP MBCS Now I saw, tho' too late, the folly of beginning a work before we count the cost and before we we judge rightly of our strength to go thro' with it - Robinson Crusoe |
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 , > > |
From: Dave P. <dpo...@li...> - 2013-12-23 21:28:21
|
Hiya Mike , On Sat, 2013-12-21 at 14:21 -0800, Mike Schilli wrote: > Hi Dave, <snip> > > Hope that helps! > Awesome, that's most definitely worth the wait. Would it be worthwhile to document this 'feature' in order to head off further such questions? Thanx for that , Best rgds , -- Dave Pointon FIAP MBCS Now I saw, tho' too late, the folly of beginning a work before we count the cost and before we we judge rightly of our strength to go thro' with it - Robinson Crusoe |
From: Mike S. <m...@pe...> - 2013-12-24 02:03:28
|
On Mon, 23 Dec 2013, Dave Pointon wrote: > Would it be worthwhile to document this 'feature' in order to head off > further such questions? I added this to the FAQ: http://feedproxy.google.com/~r/FatwalletHotDeals/~3/YyseBpP9ZeU/ Good enough? -- -- Mike Mike Schilli m...@pe... |
From: Mike S. <m...@pe...> - 2013-12-24 02:04:38
|
On Mon, 23 Dec 2013, Dave Pointon wrote: > Would it be worthwhile to document this 'feature' in order to head off > further such questions? Gah, wrong link :). I added this item to the FAQ: https://github.com/mschilli/log4perl/commit/18c615ec1c81d780faeff8b95f49494ad29dbcfa Good enough? -- -- Mike Mike Schilli m...@pe... |
From: Dave P. <dpo...@li...> - 2013-12-24 15:03:29
|
On Mon, 2013-12-23 at 18:03 -0800, Mike Schilli wrote: > On Mon, 23 Dec 2013, Dave Pointon wrote: > > > Would it be worthwhile to document this 'feature' in order to head off > > further such questions? > > Gah, wrong link :). I added this item to the FAQ: > > https://github.com/mschilli/log4perl/commit/18c615ec1c81d780faeff8b95f49494ad29dbcfa > > Good enough? > Good enough It's more than that, I couldn't have wished for anything better. Thanx for your help, Mike. May you and yours have a good xmas & new year. Best rgds , -- Dave Pointon FIAP MBCS Now I saw, tho' too late, the folly of beginning a work before we count the cost and before we we judge rightly of our strength to go thro' with it - Robinson Crusoe |