|
From: Mike S. <log...@pe...> - 2003-07-07 00:20:47
|
On Fri, 4 Jul 2003, Matthew Keene wrote:
> Definitely agree, in fact in one of the hacks that I did I created a
> get_appender_by_name method
>
> sub get_appender_by_name {
> my ($self, $appender_name) = @_ ;
> return $APPENDER_BY_NAME{$appender_name} ;
> }
>
> I don't know whether it's better from an OO interface standpoint to have
> access to the internal hash, or to be able to return individual entries
Good point. If we wanted to have it squeaky clean, however, there'd be
a lot more to do (e.g. accessors for all fields in all Appender
objects), and it's probably not worth it right now, so I kept the
method returning a hashref which maps appender names to appender
objects. I did make a minor modification to my previous post, though: I
thought that it might be cleaner to put the method into Log::Log4perl,
since the appenders returned are system- and not logger related. Here's
the patch (to be part of 0.36):
Index: Log4perl.pm
===================================================================
RCS file: /cvsroot/log4perl/Log-Log4perl/lib/Log/Log4perl.pm,v
retrieving revision 1.134
retrieving revision 1.136
diff -a -u -r1.134 -r1.136
--- Log4perl.pm 25 Jun 2003 23:42:52 -0000 1.134
+++ Log4perl.pm 7 Jul 2003 00:09:02 -0000 1.136
@@ -13,7 +13,7 @@
use constant DEBUG => 1;
-our $VERSION = '0.35';
+our $VERSION = '0.36';
# set this to '1' if you're using a wrapper
# around Log::Log4perl
@@ -280,6 +280,12 @@
return Log::Log4perl::Logger->get_logger(@args);
}
+##################################################
+sub appenders { # Get all defined appenders hashref
+##################################################
+ return \%Log::Log4perl::Logger::APPENDER_BY_NAME;
+}
+
1;
__END__
@@ -1856,6 +1862,23 @@
of C<$Log::Log4perl::caller_depth> (defaults to 0) by one for every
wrapper that's in between your application and C<Log::Log4perl>,
then C<Log::Log4perl> will compensate for the difference.
+
+=head1 Access to Internals
+
+The following methods are only of use if you want to peek/poke in
+the internals of Log::Log4perl. Be careful not to disrupt its
+inner workings.
+
+=over 4
+
+=item C<< Log::Log4perl->appenders() >>
+
+To find out which appenders are currently defined (not only
+for a particular logger, but overall), a C<appenders()>
+method is available to return a reference to a hash mapping appender
+names to their Log::Log4perl::Appender object references.
+
+=back
=head1 EXAMPLE
I've also added a test case in t/002 and a comment in Changes.
-- Mike
Mike Schilli
log...@pe...
http://perlmeister.com
http://log4perl.sourceforge.net
|