Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: trying to extend Log::Log4perl

by Bloodnok (Vicar)
on Nov 23, 2012 at 23:19 UTC ( #1005324=note: print w/ replies, xml ) Need Help??

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 :-))

Comment on Re: trying to extend Log::Log4perl
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1005324]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (14)
As of 2014-08-27 14:00 GMT
Find Nodes?
    Voting Booth?

    The best computer themed movie is:

    Results (238 votes), past polls