Bloodnok has asked for the wisdom of the Perl Monks concerning the following question:
Hi there fellow monasterians ,
I appear to have encountered an unexpected problem whilst trying to extend Log::Log4perl by way of subclassing it as in (simple form) ...
#! /usr/bin/env perl package L4P::Subclass; use Log::Log4perl qw/:no_extra_logdie_message :levels/; our @ISA = qw/Log::Log4perl/; Log::Log4perl->wrapper_register( __PACKAGE__ ); Log::Log4perl->easy_init( { name => 'LOG', file => "STDOUT", layout => '[%d - %r] %p (%c) %M:%L %m%n', level => $TRACE, } ) or die 'easy_init() failed - '; sub new { my $pkg = shift; my $log = bless Log::Log4perl->get_logger(caller()), __PACKAGE__; warn $log->get_logger(caller())->category(); return $log; } sub trace_start { my $self = shift; $self->debug("Starting with args: " . join ', ', @_); } #our $AUTOLOAD; sub AUTOLOAD { my $self = shift; (my $method = $AUTOLOAD) =~ s/.*://; Log::Log4perl->get_logger(caller())->$method(@_); } package main; my $log = L4P::Subclass->new(); $log->trace_start("Please don't let it be L4P::Subclass");
However, when the script is run, the output is
- the, not necessarily clear, problem is that although the package name and line number are correct (as in main::44), the category of the logged message is always L4P.SubClass c/w the expected value of main.L4P.Subclass at work/repos/Git/tools/lib/IBM-PTC-Core/LogTest.pl line +22. [2013/02/20 14:22:48 - 1] DEBUG (L4P.Subclass) main:::44 Starting with + args: Please don't let it be L4P::Subclass
Question is, have I done something wrong in my code or is there actually something wrong ?
As always, any help &/or hints will be gratefully received.
TIA & rgds ,
A user level that continues to overstate my experience :-))
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Subclassing L4P appears to generate fixed category log messages
by zwon (Abbot) on Feb 23, 2013 at 13:55 UTC | |
by Bloodnok (Vicar) on Feb 27, 2013 at 13:14 UTC |
Back to
Seekers of Perl Wisdom