nysus has asked for the wisdom of the Perl Monks concerning the following question:
I have the following:
{ package MyApp; use Moose; use Moose::Util qw( apply_all_roles ); with 'MooseX::Log::Log4perl'; sub BUILD { my $s = shift; # apply_all_roles($s, 'BarCollector'); # if you uncomment this li +ne, logging doesn't work anymore } sub print_something { my $self = shift; $self->log->info('This does not print when apply_all_roles is used +.'); } } { package BarCollector; use Moose::Role # does nothing } #! /usr/bin/env perl use File::HomeDir; use Log::Log4perl; BEGIN { Log::Log4perl->init_once(File::HomeDir->my_home . '/test.cfg') + }; use MyApp; my $app = MyApp->new(); $app->print_something; __END__ # test.cfg config file: log4perl.logger.MyApp=TRACE, LOG log4perl.appender.LOG=Log::Log4perl::Appender::ScreenColoredLevels log4perl.appender.LOG.layout=PatternLayout log4perl.appender.LOG.layout.ConversionPattern=%c - %m%n
As noted in the comment, when the line that contains apply_all_roles is uncommented, log messages no longer work. There are no errors.
Update: One other clue is that when I change the first line of the config file to: log4perl.rootLogger=TRACE, LOG
I get output, though the category looks something like this: Moose.Meta.Class.__ANON__.SERIAL.1
Any workaround to this?
I discovered if I slap $s->log->trace('print this'); before the apply_all_roles method is called, everything works as expected. Is there a better way?
$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: apply_all_roles method clobbering MooseX::Log::Log4perl
by 1nickt (Canon) on Jan 18, 2018 at 15:43 UTC | |
by nysus (Parson) on Jan 18, 2018 at 15:46 UTC | |
by 1nickt (Canon) on Jan 18, 2018 at 16:07 UTC |