From: J M. <jm...@gm...> - 2011-10-12 17:05:25
|
Greetings, I've recently encountered an odd issue while using Moose to create a wrapper class for Log::Log4perl that results in the logger's category somehow being returned as 'Eval.Closure', despite that I've registered the wrapper class as indicated in the documentation. I'm not sure if this is an actual issue or just something I'm missing with regards to wrapping Log::Log4perl, but here's a simplified code example that exhibits the issue: *## --------------------------------------------------------------------------------------------------------------------- { package Wrapper::Log::Log4perl; use Moose; use MooseX::Method::Signatures; use Log::Log4perl; Log::Log4perl->wrapper_register( __PACKAGE__ ); ## Attribute definitions has 'logger' => ( is => 'rw', isa => 'Log::Log4perl::Logger', ); has 'logger_cfg' => ( is => 'ro', isa => 'Maybe[Str]', ); ## Object initialization sub BUILD { my $self = shift(); unless ( Log::Log4perl->initialized() ) { $self->init( $self->logger_cfg() ); } $self->logger( Log::Log4perl->get_logger() ); } ## Method definitions method init ( Str $cfg ) { Log::Log4perl->init( $cfg ); }; __PACKAGE__->meta->make_immutable(); } ## --------------------------------------------------------------------------------------------------------------------- { package main; use Data::Dumper; my $logApi = Wrapper::Log::Log4perl->new( logger_cfg => '../Data/INI/Log/Log4perl.ini' ); print( Dumper($Log::Log4perl::Logger::LOGGERS_BY_NAME) ); } * Thanks in advance for taking a peek, and let me know if there's any more information I can provide. --J |
From: Mike S. <m...@pe...> - 2011-10-26 06:44:57
|
On Wed, 12 Oct 2011, J Mash wrote: > I've recently encountered an odd issue while using Moose to create > a wrapper class for Log::Log4perl that results in the logger's > category somehow being returned as 'Eval.Closure', despite that I've > registered the wrapper class as indicated in the documentation. Sorry for the delay on this ... this snippet doesn't compile for me because $cfg isn't defined ... can you please check if you're missing a piece (please enable use strict/use warnings). -- -- Mike Mike Schilli m...@pe... > I'm not sure if this is an actual issue or just something I'm missing >with regards to wrapping Log::Log4perl, but here's a simplified code >example that exhibits the issue: > > ##--------------------------------------------------------------------------- > ------------------------------------------ > { > package Wrapper::Log::Log4perl; > > use Moose; > use MooseX::Method::Signatures; > > use Log::Log4perl; > Log::Log4perl->wrapper_register( __PACKAGE__ ); > > ## Attribute definitions > has 'logger' => ( > is => 'rw', > isa => 'Log::Log4perl::Logger', > ); > > has 'logger_cfg' => ( > is => 'ro', > isa => 'Maybe[Str]', > ); > > ## Object initialization > sub BUILD { > my $self = shift(); > > unless ( Log::Log4perl->initialized() ) { > $self->init( $self->logger_cfg() ); > } > $self->logger( Log::Log4perl->get_logger() ); > } > > ## Method definitions > method init ( Str $cfg ) { > Log::Log4perl->init( $cfg ); > }; > > __PACKAGE__->meta->make_immutable(); > } > > > ##--------------------------------------------------------------------------- > ------------------------------------------ > { > package main; > > use Data::Dumper; > > my $logApi = Wrapper::Log::Log4perl->new( logger_cfg => > '../Data/INI/Log/Log4perl.ini' ); > > print( Dumper($Log::Log4perl::Logger::LOGGERS_BY_NAME) ); > } > > Thanks in advance for taking a peek, and let me know if there's any more > information I can provide. > --J > > |
From: Mike S. <m...@pe...> - 2011-10-26 15:49:05
|
On Tue, 25 Oct 2011, Mike Schilli wrote: > the delay on this ... this snippet doesn't compile for me > because $cfg isn't defined Gah, I had a missing module, never mind. The wrapper registration seems to work, though, here's the output of the script below: 2011/10/26 08:44:32 l4pm 54> Whoa! which prints the correct file and line number. Log4perl configuration is log4perl.category = WARN, Screen log4perl.appender.Screen = Log::Log4perl::Appender::Screen log4perl.appender.Screen.filename = test.log log4perl.appender.Screen.layout = Log::Log4perl::Layout::PatternLayout log4perl.appender.Screen.layout.ConversionPattern = %d %F{1} %L> %m %n Let me know if you're doing something different. -- -- Mike Mike Schilli m...@pe... #!/usr/local/bin/perl -w use strict; ##--------------------------------------------------------------------------- { package Wrapper::Log::Log4perl; use local::lib; use Moose; use MooseX::Method::Signatures; use Log::Log4perl; Log::Log4perl->wrapper_register( __PACKAGE__ ); ## Attribute definitions has 'logger' => ( is => 'rw', isa => 'Log::Log4perl::Logger', ); has 'logger_cfg' => ( is => 'ro', isa => 'Maybe[Str]', ); ## Object initialization sub BUILD { my $self = shift(); unless ( Log::Log4perl->initialized() ) { $self->init( $self->logger_cfg() ); } $self->logger( Log::Log4perl->get_logger() ); } ## Method definitions method init ( Str $cfg ) { Log::Log4perl->init( $cfg ); }; __PACKAGE__->meta->make_immutable(); } ##--------------------------------------------------------------------------- { package main; use Data::Dumper; my $logApi = Wrapper::Log::Log4perl->new( logger_cfg => 'test.l4p' ); $logApi->logger->warn("Whoa!"); } >> I've recently encountered an odd issue while using Moose to create >> a wrapper class for Log::Log4perl that results in the logger's >> category somehow being returned as 'Eval.Closure', despite that I've >> registered the wrapper class as indicated in the documentation. |