Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Subclassing L4P appears to generate fixed category log messages

by zwon (Abbot)
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:

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

Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1020303]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2018-05-21 19:46 GMT
Find Nodes?
    Voting Booth?