in reply to Re: Log::Log4perl - changing an appenders threshold
in thread Log::Log4perl - changing an appenders threshold

Thanks for the suggestion, but there are no methods available on the $log object that will modify the appenders, only methods to adjust the logger itself.

I have however now found a solution, to set the SCREEN appender to threshold of 'debug' : $Log::Log4perl::Logger::APPENDER_BY_NAME{'LOGFILE'}->threshold('DEBUG')

This does work as I required.

I believe that the method : Log::Log4perl->appender_by_name('SCREEN')->threshold('DEBUG') amends the 'actual appender' - however because these appenders are 'wrapped' it needs to be the 'wrapper class' itself that needs adjusted, to give me the desired result.

I had achieved this initially by modifying the objects data directly using : ${$Log::Log4perl::Logger::APPENDER_BY_NAME{'SCREEN'}}{'level'} = 20000

This is what initially seemed to be suggested at : http://log4perl.sourceforge.net/releases/Log-Log4perl/docs/html/Log/Log4perl.html#356d5 : "The previously mentioned method appender_by_name() returns a referrence to the real appender object. If you want access to the wrapper class (e.g. if you want to modify the appender's threshold), use the hash $Log::Log4perl::Logger::APPENDER_BY_NAME{...} instead, which holds references all appender wrapper objects."

After re-reading a few times, Im now aware of the threshold method on the actual 'wrapper class' ( $Log::Log4perl::Logger::APPENDER_BY_NAME{'LOGFILE'} ) and can therefore also use the 'friendly name' ( ie DEBUG/TRACE/WARN ) rather than a numeric ( 30000/20000/5000 )

Hope someone also finds this useful !

  • Comment on Re^2: Log::Log4perl - changing an appenders threshold