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;
>>
>
>