Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1005324]
[Discipulus]: choroba the Tk client print out an educated error message that it cant connect..
[Discipulus]: Can't connect to 80Invalid argument at ..perl5.26.64bit/ perl/vendor/lib/ LWP/Protocol/http. pm line 46, <__ANONIO__> line 34500.

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2017-10-24 10:49 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (288 votes). Check out past polls.