Skip Menu |
 
rt.cpan.org will be shut down on March 1st, 2021.

This queue is for tickets about the MooseX-Log-Log4perl CPAN distribution.

Report information
The Basics
Id: 77783
Status: open
Priority: 0/
Queue: MooseX-Log-Log4perl

People
Owner: lammel [...] cpan.org
Requestors: joni.salonen [...] qindel.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Incorrect message categories in inheritance hierarchies
Date: Tue, 12 Jun 2012 18:05:47 +0200
To: bug-MooseX-Log-Log4perl [...] rt.cpan.org
From: Joni Salonen <joni.salonen [...] qindel.com>
Download (untitled) / with headers
text/plain 803b
Messages logged in a parent class have a category that corresponds to the child class. They should have the category of the parent class. See the code example below. Expected output for the sample: Category=Parent Actual output: Category=Child Code: ------------------------------- package Parent; use Moose; with 'MooseX::Log::Log4perl'; sub method { shift->log->info('Parent message'); } package Child; use Moose; extends 'Parent'; package main; use Log::Log4perl; my $conf = q( log4perl.logger=INFO, screen log4perl.appender.screen=Log::Log4perl::Appender::Screen log4perl.appender.screen.layout=Log::Log4perl::Layout::PatternLayout log4perl.appender.screen.layout.ConversionPattern=Category=%c%n ); Log::Log4perl::init(\$conf); my $c = Child->new; $c->method;
Download (untitled) / with headers
text/plain 1.5k
Thanks for reporting, but I can't follow your expectations. You create a instance of child here, and run the method "method" on the child class instance, which of course will run inherited method "method". Still the category is initialized as the class name by default. So the result is expected and ok. You would need to explicitly set the category for the logger if you wan't this behaviour to be different (look at the "log" method in MooseX::Log::Log4perl to get a picture). Unless I got something wrong I'm resolving this and may add some more tests showing the expected behaviour for this scenario (non overridden method in child instance). Cheers +rl On Tue Jun 12 12:06:03 2012, joni.salonen@qindel.com wrote: Show quoted text
> Messages logged in a parent class have a category that corresponds to > the child class. They should have the category of the parent class. See > the code example below. > > Expected output for the sample: > Category=Parent > > Actual output: > Category=Child > > Code: > ------------------------------- > package Parent; > use Moose; > > with 'MooseX::Log::Log4perl'; > > sub method { > shift->log->info('Parent message'); > } > > package Child; > use Moose; > extends 'Parent'; > > package main; > > use Log::Log4perl; > > my $conf = q( > log4perl.logger=INFO, screen > log4perl.appender.screen=Log::Log4perl::Appender::Screen > log4perl.appender.screen.layout=Log::Log4perl::Layout::PatternLayout > log4perl.appender.screen.layout.ConversionPattern=Category=%c%n > ); > Log::Log4perl::init(\$conf); > > my $c = Child->new; > > $c->method; >
Download (untitled) / with headers
text/plain 1.9k
You might also be interested in "%M" placeholder in Log4perl, which will give you the function being called (e.g. "Parent::method" in your case, although the category would be "Child" for a call on $child->method). Cheers +rl On Wed Jun 27 14:20:27 2012, LAMMEL wrote: Show quoted text
> Thanks for reporting, but I can't follow your expectations. > > You create a instance of child here, and run the method "method" on the > child class instance, which of course will run inherited method > "method". Still the category is initialized as the class name by default. > > So the result is expected and ok. > > You would need to explicitly set the category for the logger if you > wan't this behaviour to be different (look at the "log" method in > MooseX::Log::Log4perl to get a picture). > > Unless I got something wrong I'm resolving this and may add some more > tests showing the expected behaviour for this scenario (non overridden > method in child instance). > > Cheers > > +rl > > On Tue Jun 12 12:06:03 2012, joni.salonen@qindel.com wrote:
> > Messages logged in a parent class have a category that corresponds to > > the child class. They should have the category of the parent class. See > > the code example below. > > > > Expected output for the sample: > > Category=Parent > > > > Actual output: > > Category=Child > > > > Code: > > ------------------------------- > > package Parent; > > use Moose; > > > > with 'MooseX::Log::Log4perl'; > > > > sub method { > > shift->log->info('Parent message'); > > } > > > > package Child; > > use Moose; > > extends 'Parent'; > > > > package main; > > > > use Log::Log4perl; > > > > my $conf = q( > > log4perl.logger=INFO, screen > > log4perl.appender.screen=Log::Log4perl::Appender::Screen > >
log4perl.appender.screen.layout=Log::Log4perl::Layout::PatternLayout Show quoted text
> > log4perl.appender.screen.layout.ConversionPattern=Category=%c%n > > ); > > Log::Log4perl::init(\$conf); > > > > my $c = Child->new; > > > > $c->method; > >
> >
Subject: Re: [rt.cpan.org #77783] Incorrect message categories in inheritance hierarchies
Date: Mon, 02 Jul 2012 11:04:44 +0200
To: bug-MooseX-Log-Log4perl [...] rt.cpan.org
From: Joni Salonen <joni.salonen [...] qindel.com>
Download (untitled) / with headers
text/plain 2.7k
Hi Roland, As you know, Log::Log4perl by default uses the current module name as the category, which is useful because messages logged in parent classes will have a predictable category. For example, if you change the Parent class in the example below to use Log4perl directly you get the output "Category=Parent", no matter how many child classes Parent has and through which object Parent::method ends up being called: package Parent; use Moose; sub log { Log::Log4perl->get_logger } sub method { # Category=Parent, always & forever shift->log->info('Parent message'); } If the category changes in child classes, as in MooseX::Log::Log4perl, you lose this feature, and log messages that the parent class emits can be discarded or routed to appenders you don't expect. It's great that you can set the category by hand, and it would be even better if this difference between the features of Log::Log4perl and MooseX::Log::Log4perl was documented. I do appreciate that some people may actually want the current behaviour. Regards, Joni On 06/27/2012 08:20 PM, Roland Lammel via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=77783 > > > Thanks for reporting, but I can't follow your expectations. > > You create a instance of child here, and run the method "method" on the > child class instance, which of course will run inherited method > "method". Still the category is initialized as the class name by default. > > So the result is expected and ok. > > You would need to explicitly set the category for the logger if you > wan't this behaviour to be different (look at the "log" method in > MooseX::Log::Log4perl to get a picture). > > Unless I got something wrong I'm resolving this and may add some more > tests showing the expected behaviour for this scenario (non overridden > method in child instance). > > Cheers > > +rl > > On Tue Jun 12 12:06:03 2012, joni.salonen@qindel.com wrote:
>> Messages logged in a parent class have a category that corresponds to >> the child class. They should have the category of the parent class. See >> the code example below. >> >> Expected output for the sample: >> Category=Parent >> >> Actual output: >> Category=Child >> >> Code: >> ------------------------------- >> package Parent; >> use Moose; >> >> with 'MooseX::Log::Log4perl'; >> >> sub method { >> shift->log->info('Parent message'); >> } >> >> package Child; >> use Moose; >> extends 'Parent'; >> >> package main; >> >> use Log::Log4perl; >> >> my $conf = q( >> log4perl.logger=INFO, screen >> log4perl.appender.screen=Log::Log4perl::Appender::Screen >> log4perl.appender.screen.layout=Log::Log4perl::Layout::PatternLayout >> log4perl.appender.screen.layout.ConversionPattern=Category=%c%n >> ); >> Log::Log4perl::init(\$conf); >> >> my $c = Child->new; >> >> $c->method; >>
> >


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.