Hello, I am trying to setup a logger that has multiple appenders/categories (for example, one that goes to a file and one that goes to stdout). However, I also need to be able to modify the appenders after the initialization. For example, I want to update the log level and update the file name after initialization. I have found several examples of how to create the logger (and I have been successful in creating and using them), but I cannot figure out how to modify the appenders. I have worked through the documentation and help on these sites:
https://metacpan.org/pod/Log::Log4perl https://www.perl.com/pub/2002/09/11/log4perl.html/ https://www.perlmonks.org/?node_id=1198853
but I cannot find a combination that works. Lets say I have this:
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");
How do I then change the level and file for each of these appenders? I have tried these example:
Log::Log4perl::Logger::APPENDER_BY_NAME{'STDOUT'}->threshold($TRACE); Log::Log4perl->appender_by_name('STDOUT')->threshold($TRACE);
but they did not work. Alternatively, I tried this example:
https://metacpan.org/pod/Log::Log4perl#Advanced-configuration-within-P +erl
and I got the logging to work, but I could not change the appender. What am I missing or doing wrong? Thanks

-- 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>

In reply to log4perl help by drohr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.