http://www.perlmonks.org?node_id=1005324


in reply to trying to extend Log::Log4perl

Hi ,
It's a bit late I know buuuut....I'm going to do this anyway:-)

Having encountered a not unrelated problem myself, I did a little investigating and AFAICT, L4P appears to construct it's methods dynamically (using closures) and doesn't make them available to an inheriting bespoke logger wrapper package via the standard route e.g. @ISA/SUPER:: etc., so they are available only to the L4P instance itself.

The only 'obvious' way I could think of at the time was to utilise MyWrapper::AUTOLOAD to dispatch non-overridden L4P method calls to the logger object via a get_logger(class) call and let L4P deal with unknown methods etc. e.g. in a manner something similar to ...

package MyWrapper; use warnings; use strict; use autodie; # Not strictly necessary, but JIC I forget later use base qw/Log::Log4perl; our $AUTOLOAD; sub get_logger { my $self = shift; return Log::Log4perl->get_logger(@_); # or $self->SUPER::get_logge +r(@_) but that requires # sufficient knowledge of L4 +P to know/realise that # get_logger is a standard e +xportable function } sub trace_beg { my $self = shift; __PACKAGE__->debug("Starting with args: " . join ' ', @_); } sub AUTOLOAD { my $self = shift; (my $method = $AUTOLOAD) =~ s,.*::,,; my $class = caller; local $Log::Log4perl::Caller_depth = $Log::Log4perl::caller_depth ++ 1; goto $self->get_logger($class)->$method(@_); } 1;
The usual caveat emptor applies, but that's close to the way I managed to do it - less an awful lot of extraneous code.

Hope that helps ...

A user level that continues to overstate my experience :-))