Hi Mike. According to the docs, it ought to have worked but it doesn't.
I've got a config like: ------ begin config ------ layout = %d{yyyy-MM-ddTHH:mm:ss} %P %p %c %H %m%n # Assign various things to various appenders log4perl.rootlogger = TRACE, FILE, SCREEN log4perl.logger.deactivated = OFF, SCREENDEBUG # Log everything to a file log4perl.appender.FILE = Log::Log4perl::Appender::File log4perl.appender.FILE.filename = sub { main::get_log_name(); } log4perl.appender.FILE.mode = clobber log4perl.appender.FILE.Threshold = TRACE log4perl.appender.FILE.layout = Log::Log4perl::Layout::PatternLayout log4perl.appender.FILE.layout.ConversionPattern = FILE ${layout} log4perl.appender.SCREEN = Log::Log4perl::Appender::Screen log4perl.appender.SCREEN.Threshold = ERROR log4perl.appender.SCREEN.layout = Log::Log4perl::Layout::PatternLayout log4perl.appender.SCREEN.layout.ConversionPattern = SCREEN ${layout} log4perl.appender.SCREENDEBUG = Log::Log4perl::Appender::ScreenColoredLevels log4perl.appender.SCREENDEBUG.layout = Log::Log4perl::Layout::PatternLayout log4perl.appender.SCREENDEBUG.layout.ConversionPattern = SCREENDEBUG ${layout} ------ end ------ The code looks like: ------ begin code ------ Log::Log4perl::init_and_watch($CONFIG_FILE, 10); my $logger = Log::Log4perl->get_logger(); if ( $screen eq 'SCREENDEBUG' ) { my $app = Log::Log4perl->appender_by_name('SCREENDEBUG'); $logger->add_appender($app); eval { $app = Log::Log4perl->appender_by_name('SCREEN'); Log::Log4perl::Logger->get_root_logger()->remove_appender($app); }; if ($@) { warn("can't remove SCREEN appender: $@"); } } The first part (adding SCREENDEBUG workd; the second doesn't. The error I get is: can't remove SCREEN appender: No such appender: Log::Log4perl::Appender::Screen=HASH(0x843cf28) at //ms/dist/perl5/PROJ/Log-Log4perl/1.13/lib/perl5/Log/Log4perl/Logger.pm line 607. Which is strange as, running under the debugger, I can see both appenders listed in the root logger. Any ideas? ------ end ------ Thomas Erskine Consultant | Technology 2000 Barrington St | Suite 300 | Floor 04 Halifax, NS B3J3K1 Phone: +1 902 442-4709 [EMAIL PROTECTED] > -----Original Message----- > From: Erskine, Thomas (IT) > Sent: Thursday, October 30, 2008 12:03 PM > To: 'Mike Schilli' > Cc: log4perl-devel@lists.sourceforge.net > Subject: RE: [log4perl-devel] activating appenders > > Hi Mike. > > I want to have the appender defined in the configuration for > doccumentation and because having log configuration external > to the program is (at least) half the point of a logging system IMHO. > > The problem with setting a threshold on the appender to cause > it not ot log is that I don't see a way to programmatically > set the threshold to a specific level. It can be bumped up > or down, but that requires the program to know where the > threshold was set in the configuration. I.E. configuration > in the program, which I'm trying to avoid. > > The best I've been able to come up with is to define a logger > with a threshold which won't log, call it deactivated, and > assign this appender to it. Then to activate this appender, > I can use appender_by_name(...) and > get_root_logger()->add_appender(...). It took me a while to > find it as get_root_logger is only defined on > Log::Log4perl::Logger, not in Log::Log4perl. > > Thomas Erskine > Consultant | Technology > 2000 Barrington St | Suite 300 | Floor 04 Halifax, NS B3J3K1 > Phone: +1 902 442-4709 > [EMAIL PROTECTED] > > > > -----Original Message----- > > From: Mike Schilli [mailto:[EMAIL PROTECTED] > > Sent: Wednesday, October 29, 2008 5:29 PM > > To: Erskine, Thomas (IT) > > Cc: log4perl-devel@lists.sourceforge.net > > Subject: Re: [log4perl-devel] activating appenders > > > > On Wed, 29 Oct 2008, Erskine, Thomas (IT) wrote: > > > > > I want to be able to define an appender in the log4perl > > config file, > > > but not activated and then activate it programmatically However, > > > Log::Log4perl->appender_by_name('SCREENDEBUG') returns undef. > > > > > > I guess I could add SCREENDEBUG to the log4perl.logger line > > and define > > > it with a threshold which won't log anything and then bump the > > > threshold up at runtime, but it seems wrong somehow. > > > > An appender that's not assigned to any logger in the > configuration is > > ignored by Log4perl at this point -- I think that using a > threshold, > > as you've suggested, is a perfectly valid solution, though. > > > > Alternatively, you can define the appender programmatically > and add it > > to the logger via add_appender(). > > > > -- Mike > > > > Mike Schilli > > [EMAIL PROTECTED] > > -------------------------------------------------------- NOTICE: If received in error, please destroy and notify sender. Sender does not intend to waive confidentiality or privilege. Use of this email is prohibited when received in error. ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ log4perl-devel mailing list log4perl-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/log4perl-devel