From: Ronald of S. <aus...@ye...> - 2009-02-18 13:46:10
|
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'); Reason for this probably slightly unusual way of using Log::Log4perl is the following: 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). 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 <aus...@ye...> There are 10 types of people in the world: those who understand binary and those who don't. |