drohr has asked for the wisdom of the Perl Monks concerning the following question:
but I cannot find a combination that works. Lets say I have this:https://metacpan.org/pod/Log::Log4perl https://www.perl.com/pub/2002/09/11/log4perl.html/ https://www.perlmonks.org/?node_id=1198853
How do I then change the level and file for each of these appenders? I have tried these example:use Log::Log4perl; sub init() { Log::Log4perl->easy_init( { level => $DEBUG, file => ">>test.log", category => "FILE" }, { level => $DEBUG, file => "STDOUT", category => "STDOUT" } ); } sub getLogger { my ($category) = @_; my $logger = Log::Log4perl->get_logger($category); return $logger; } init(); my $stdout_logger = getLogger(STDOUT); $stdout_logger->info("testing stdout logger"); my $file_logger = getLogger(FILE); $file_logger->info("testing file logger");
but they did not work. Alternatively, I tried this example:Log::Log4perl::Logger::APPENDER_BY_NAME{'STDOUT'}->threshold($TRACE); Log::Log4perl->appender_by_name('STDOUT')->threshold($TRACE);
and I got the logging to work, but I could not change the appender. What am I missing or doing wrong? Thankshttps://metacpan.org/pod/Log::Log4perl#Advanced-configuration-within-P +erl
-- UPDATE --
http://log4perl.sourceforge.net/releases/Log-Log4perl/docs/html/Log/Log4perl/Appender/File.html
Here is how you change the file in an appender at run time:
<code> Log::Log4perl->appender_by_name('FILE')->file_switch('test2.log'); <code>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: log4perl help
by Anonymous Monk on Mar 03, 2021 at 00:20 UTC | |
by drohr (Acolyte) on Mar 03, 2021 at 13:46 UTC | |
by Anonymous Monk on Mar 03, 2021 at 14:05 UTC | |
by drohr (Acolyte) on Mar 03, 2021 at 16:23 UTC | |
by jcb (Parson) on Mar 04, 2021 at 03:14 UTC | |
|