perl - How can I change a log4perl appender's filters at run time? -


i'v been trying figure out if can change appender's filter @ run-time i've defined via configuration file.

log4perl.filter.m1               = log::log4perl::filter::levelmatch log4perl.filter.m2               = log::log4perl::filter::levelmatch log4perl.filter.m1.leveltomatch  = info log4perl.filter.m1.acceptonmatch = true log4perl.filter.m2.leveltomatch  = warn log4perl.filter.m2.acceptonmatch = true log4perl.filter.myboolean0       = log::log4perl::filter::boolean log4perl.filter.myboolean0.logic = m1 log4perl.filter.myboolean1       = log::log4perl::filter::boolean log4perl.filter.myboolean1.logic = m1 || m2  log4perl.appender.screen.filter  = myboolean0  

i'd change filter myboolean0 screen myboolean1, after program has started running.

poking @ appender_by_name hash screen using data::dumper shows following:

$var1 = bless( {      'appender' => bless( {                             'filter' => 'myboolean0',                             'color' => { ... ...      'filter' => bless( {·                           'params' => {·                                         'm3' => bless( {·                                                          'leveltomatch' => 'error',                                                          'name' => 'm3',                                                          'acceptonmatch' => 1                                                        }, 'log::log4perl::filter::levelmatch' ),                                         'm1' => bless( {·                                                          'leveltomatch' => 'info',                                                          'name' => 'm1',                                                          'acceptonmatch' => 1                                                        }, 'log::log4perl::filter::levelmatch' ),                                         'm2' => bless( {·                                                          'leveltomatch' => 'warn',                                                          'name' => 'm2',                                                          'acceptonmatch' => 1                                                        }, 'log::log4perl::filter::levelmatch' )                                       },                           'name' => 'myboolean0',                           'eval_func' => sub { "dummy" },                           'logic' => 'm1 || m2 || m3'                         }, 'log::log4perl::filter::boolean' ),      'warp_message' => undef,      'name' => 'screen'    }, 'log::log4perl::appender' ); 

but mucking hash seems hackish me. there better way change appender's filters?

you may use undocumented appender's property filter:

$log::log4perl::logger::appender_by_name{'screen'}->filter(     log::log4perl::filter::by_name('myboolean1') ); 

also may use 2 appenders:

log4perl.appender.screen0.filter = myboolean0 log4perl.appender.screen1.filter = myboolean1 

and change in runtime:

$logger->remove_appender('screen0', 1); $logger->add_appender(     log::log4perl::config::create_appender_instance(         $log::log4perl::config::old_config,         'screen1',         \%log::log4perl::logger::appender_by_name     ) ); 

Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -