Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Subclassing L4P appears to generate fixed category log messages

by zwon (Monsignor)
on Feb 23, 2013 at 13:55 UTC ( #1020303=note: print w/ replies, xml ) Need Help??


in reply to Subclassing L4P appears to generate fixed category log messages

Your problem starts here:

my $log = bless Log::Log4perl->get_logger(caller()), __PACKAGE__;

You're subclassing Log::Log4perl package, but in constructor you're creating Log::Log4perl::Logger object and reblessing it into L4P::Subclass. I think you should in L4P::Subclass implement your own get_logger method which will return L4P::Subclass::Logger object.

Later in AUTOLOAD you're ignoring this logger object and creating a new one:

Log::Log4perl->get_logger(caller())->$method(@_);
but AUTOLOAD is called from your package from trace_start, so category is "L4P.Subclass" and not main. You can replace it with caller(1) or just use get_logger() as Log::Log4perl will automatically skip frames belonging to your module because you've registered it as wrapper. But in order this to work you should also fix the constructor, something as simple as:
sub new { return bless {}, shift; }
will do the thing, reblessing Logger object into L4P::Subclass somehow confuses Log4perl and AUTOLOAD invokes itself recursively.

PS: also note, that you can create custom log levels. I can't find documentation, but the code is in Log::Log4perl::Logger


Comment on Re: Subclassing L4P appears to generate fixed category log messages
Select or Download Code
Re^2: Subclassing L4P appears to generate fixed category log messages
by Bloodnok (Vicar) on Feb 27, 2013 at 13:14 UTC
    TFT, I take your point about the call to bless() - I came to the same conclusion as yourself and blessed an anon scalar into the Subclass - which appears to correct (or, at least) avoid the confusion to L4P.

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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2014-12-28 12:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (181 votes), past polls