On Wed, 18 Feb 2009, Ronald of Steiermark wrote: > Reason for this probably slightly unusual way of using Log::Log4perl > is the following:
Hi Ronald, indeed, you're using Log4perl in a very unusual, not to say confusing way. What you think is a 'logger' is really an appender in Log4perl lingo. An appender has no concept of a level like 'debug', only loggers do. An appender only has a log() method, and it will normally log the message you're passing to it unconditionally. The reason why you get the error message 'on an undefined value' is an internal autoload mechanism within the appender that's not defined in your case. The error message is confusing and needs to be fixed, what it should say instead is that logdebug() doesn't exist. Ideally, you would integrate your logging needs into the main log4perl configuration -- can you explain in more detail why this isn't possible? -- Mike Mike Schilli m...@perlmeister.com > My application uses one common logging facility (hence the easy_init). > Certain parts of the application want to create occasionally their > various other logfiles with their own layout and shorter lifetime than > the common logging system (demonstrated here by > the variable $logger). This is the condensed code of my application > just for demonstrating my problem: > > use strict; > use warnings; > use Log::Log4perl qw(:easy); > use Log::Log4perl::Appender::File; > Log::Log4perl->easy_init({file=>'STDOUT',layout => '%d{HH:mm} %m%n', > level=>$DEBUG}); > my $logger=Log::Log4perl::Appender::File->new(filename => "dummy.log", > mode => 'clobber'); > $logger->log(message=>"test\n"); > $logger->layout(Log::Log4perl::Layout::PatternLayout->new('%c %C > %m%n')); > $logger->log(message => "abc"); > $logger->logdebug('xyz'); > > > Running this program results in a file dummy.log containing > > test > abc > > and the message > > Can't call method "logdebug" on an undefined value > > Now my questions: > > (1) Why does the second call to log() not obey the pattern layout I have > defined the line before? > After all, a Appender::File inherits from Appender, and hence layout() > should have the desired > effect. > > (2) Why does the error message say "on an undefined value", when $logger > (the object where method is > called on) is obviously not undefined? > > (3) I guess one of my mistakes is that Appender::File is not a suitable > logger type for my purpose. > Should I use a different logger instead, and if yes, which one? > > Ronald > -- > Ronald Fischer <austria_ru...@yepmail.net> > > There are 10 types of people in the world: those who understand binary and > those who don't. > > > ------------------------------------------------------------------------------ > Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA > -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise > -Strategies to boost innovation and cut costs with open source participation > -Receive a $600 discount off the registration fee with the source code: SFAD > http://p.sf.net/sfu/XcvMzF8H > _______________________________________________ > log4perl-devel mailing list > log4perl-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/log4perl-devel > ------------------------------------------------------------------------------ Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise -Strategies to boost innovation and cut costs with open source participation -Receive a $600 discount off the registration fee with the source code: SFAD http://p.sf.net/sfu/XcvMzF8H _______________________________________________ log4perl-devel mailing list log4perl-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/log4perl-devel