Skip Menu |

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

Report information
The Basics
Id: 52913
Status: resolved
Priority: 0/
Queue: Log-Log4perl

People
Owner: Nobody in particular
Requestors: MSCHILLI [...] cpan.org
Cc:
AdminCc:

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



Subject: get_logger() category fetching in wrapper classes changed
This bug was originally reported by Martin Evans on the log4perl mailing list, listing it here for tracking purposes: I'm only sending this on the off chance someone here might be interested - I've sorted the problem out at my end. We've been using Log::Log4perl 1.25 and previous versions for ages but moved to a new development machine. The old one was perl 5.8.8 and Log::Log4perl 1.25 and the new one is perl 5.10.0 and Log::Log4perl 1.26 (I'm not sure the Perl version matters but I have not tested that). Since the upgrade we are getting no logging in one of the files we expected to get it. After a bit of searching around I discovered the module we were using was doing this: local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 1; $h{logger} = Log::Log4perl->get_logger(); and the fix was to change the order of those lines. I've no idea why it works on one machine and not the other but I thought someone might be interested. The module in question was DBIx::Log4perl. Martin -- Martin J. Evans Easysoft Limited
It was ending up with "main" and the category in the following code instead of DBIx::Log4perl. sub get_logger { # Get an instance (shortcut) ################################################## # get_logger() can be called in the following ways: # # (1) Log::Log4perl::get_logger() => () # (2) Log::Log4perl->get_logger() => ("Log::Log4perl") # (3) Log::Log4perl::get_logger($cat) => ($cat) # # (5) Log::Log4perl->get_logger($cat) => ("Log::Log4perl", $cat) # (6) L4pSubclass->get_logger($cat) => ("L4pSubclass", $cat) # Note that (4) L4pSubclass->get_logger() => ("L4pSubclass") # is indistinguishable from (3) and therefore can't be allowed. # Wrapper classes always have to specify the category explicitely. my $category; if(@_ == 0) { # 1 $category = scalar caller($Log::Log4perl::caller_depth); } elsif(@_ == 1) { # 2, 3 if($_[0] eq __PACKAGE__) { # 2 $category = scalar caller($Log::Log4perl::caller_depth); } else { $category = $_[0]; } } else { # 5, 6 $category = $_[1]; } # Delegate this to the logger module return Log::Log4perl::Logger->get_logger($category); } Here is an example: 1.pl ==== use Log::Log4perl qw(get_logger :levels); use DBIx::Log4perl; Log::Log4perl->init_and_watch('x.conf', 60); my $a = DBIx::Log4perl->new(); Log4perl.pm (put this in a dir called DBIx) =========== package DBIx::Log4perl; sub new { local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 1; $h = Log::Log4perl->get_logger(); $h->debug("log msg"); } 1; x.conf ====== log4perl.logger=ERROR log4perl.logger.Server = INFO log4perl.logger.DBIx.Log4perl=DEBUG, X1 log4perl.appender.X1=Log::Log4perl::Appender::File log4perl.appender.X1.filename=dbix.log log4perl.appender.X1.mode=append log4perl.appender.X1.utf8 = 1 log4perl.appender.X1.umask = sub { 0002 } log4perl.appender.X1.layout=Log::Log4perl::Layout::PatternLayout log4perl.appender.X1.layout.ConversionPattern=%d %p> %F{1}:%L %M - %m%n then run perl -I/dir_where_DBIx_dir_is 1.pl nothing comes out in log. Change the depth after get_logger and it works. Martin -- Martin J. Evans Easysoft Limited
On Sat Dec 19 16:22:24 2009, MSCHILLI wrote: Show quoted text
> Here's the proposed fix: > > >
http://github.com/mschilli/log4perl/commit/8ad3fbae60a4667aba848eb545c66339aeff161a This seems to work fine for me now. Thanks. Martin -- Martin J. Evans Wetherby, UK
Going out with next release (1.27)