I have a Log4perl configuration file that looks like...
log4perl.rootLogger=DEBUG, Screen, FileRotate
log4perl.appender.Screen=Log::Log4perl::Appender::Screen
log4perl.appender.Screen.stderr=0
log4perl.appender.Screen.layout=Log::Log4perl::Layout::PatternLayout
log4perl.appender.Screen.layout.ConversionPattern = %d %-1.1p %P %H %m
+%n
log4perl.appender.FileRotate=Log::Dispatch::FileRotate
log4perl.appender.FileRotate.filename=$logFileDir/$logFileName
log4perl.appender.FileRotate.mode=append
log4perl.appender.FileRotate.autoflush=1
log4perl.appender.FileRotate.DatePattern=yyyy-MM-dd-HH
log4perl.appender.FileRotate.layout=Log::Log4perl::Layout::PatternLayo
+ut
log4perl.appender.FileRotate.layout.ConversionPattern = %d %-1.1p %P %
+H %m%n
I know that I can have multiple configuration files and load different ones based on my application startup parameters. But I'd rather take a different approach.
Is it possible to programmatically turn off an appender?
For example, I would like to be able to turn off the Screen appender (and have only the FileRotate appender active) if the application is being started as a deamon.
Is this possible? I've been reading through the POD but can find nothing that might give me this capability.
Here is a snippet of code I would like to implement...
Log::Log4perl::init(\$log_conf);
my $log = Log::Log4perl->get_logger;
if ($opt{d}) { # if starting as a daemon...
# turn off the Screen appender
# ??
# change the log level
use Log::Log4perl::Level;
$log->level($INFO);
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.