|
From: Mike S. <log...@pe...> - 2003-07-03 18:50:19
|
On Thu, 3 Jul 2003, Matthew Keene wrote:
> I want to be able to access the details of a given appender attached
> to a logger. I can get the names of the appenders via
> $logger->appender_names, but I would like to get access to the actual
> appender details. Specifically I'm trying to get the filename which is
> defined in a configuration file for a specific logger. I've been able
> to hack it by adding the following line to the add_appender method in
> Logger.pm
>
> $self->{appenders} = \%APPENDER_BY_NAME ;
>
> and then accessing it from the program for the logger Logfile by
>
> $logger->{appenders}{Logfile}{appender}{filename} ;
>
> Is there a way of doing this that doesn't involve hacking the code ?
> If not, would you consider adding this to the log4perl code ?
There's currently no 'official' way to do that, but Perl certainly
lets you take a peek without hacking Log::Log4perl:
%Log::Log4perl::Logger::APPENDER_BY_NAME
is available. For better encapsulation, we should probably provide
an appenders() method returning a ref to the hash, as in the patch below.
Thoughts?
-- Mike
Mike Schilli
log...@pe...
http://perlmeister.com
http://log4perl.sourceforge.net
Index: Logger.pm
===================================================================
RCS file: /cvsroot/log4perl/Log-Log4perl/lib/Log/Log4perl/Logger.pm,v
retrieving revision 1.49
diff -a -u -r1.49 Logger.pm
--- Logger.pm 10 Jun 2003 07:02:41 -0000 1.49
+++ Logger.pm 3 Jul 2003 18:49:22 -0000
@@ -456,6 +456,12 @@
}
##################################################
+sub appenders {
+##################################################
+ return \%APPENDER_BY_NAME;
+}
+
+##################################################
sub has_appenders {
##################################################
my($self) = @_;
|