|
From: Mike S. <m...@pe...> - 2006-02-02 21:47:10
|
On Thu, 2 Feb 2006, Enzer, Matisse BGI SF wrote:
> I have a logger with two appenders; Screen and File. Initially both
> appenders have a threshold of DEBUG. I'd like to change the threshold
> of the Screen appender (just for this logger object) to WARN, at run
> time. Something like this:
>
> my $logger = Log::Log4perl->get_logger($category);
> $logger->warn("connecting to insecure server"); # logged by both
> Screen and File appenders
> .
> .
> .
> $logger->new_threshold('Screen',$WARN);
> $logger->info("Receiving data from $server_name"); # logged only by
> File appender
> $logger->warn("Disconnecting from $server_name"); # Logged by Screen and
> File appenders.
>
> Is that reasonable? Do-able?
Sure! (using screen appenders for simplicity):
use Log::Log4perl qw(:easy);
my $conf = q{
log4perl.logger.mycat = DEBUG, Screen1, Screen2
log4perl.appender.Screen1 = Log::Log4perl::Appender::Screen
log4perl.appender.Screen1.layout = SimpleLayout
log4perl.appender.Screen1.Threshold = DEBUG
log4perl.appender.Screen2 = Log::Log4perl::Appender::Screen
log4perl.appender.Screen2.layout = SimpleLayout
log4perl.appender.Screen2.Threshold = DEBUG
};
Log::Log4perl->init(\$conf);
my $logger = get_logger("mycat");
$logger->debug("both appenders");
Log::Log4perl->appender_thresholds_adjust(+1, ['Screen1']);
$logger->debug("one appender");
$logger->info("both appenders again");
prints:
DEBUG - both appenders
DEBUG - both appenders
DEBUG - one appender
INFO - both appenders again
INFO - both appenders again
-- Mike
Mike Schilli
m...@pe...
|