From: Mike S. <m...@pe...> - 2006-06-16 16:31:55
|
On Thu, 15 Jun 2006, Roger Day wrote: > My logging situation is complex - the pseudo-code looks like this: > > <initialise main log> > log to main log > : : > for 1 to n of builds > log to main log > : : > <swap for local log for building component> > log to local log > : : > <swap to main log> > log to main log > : : > > so I'm swapping appenders every so often, which is why I didn't use > Log::Log4perl->init. In fact, I destroy the previous local-log appender. It's not exactly a common thing to do in Log4perl, but you can certainly do it :). I'd rather use a buffer appender for this purpose, though, and I would just check the buffer every so often and write its content to the appropriate file. This way, you put the logic out of Log4perl and into your application, where it probably belongs in the first place. But YMMV, of course. > Or maybe I could us Log::Log4perl->init every time? init() is usually only called once at the start of the program. -- Mike Mike Schilli m...@pe... > > Cheers > Roger > At 15/06/2006 07:52:05, Mike Schilli <m...@pe...> wrote: > >On Wed, 14 Jun 2006, Roger Day wrote: > > > >> my $appender = Log::Log4perl::Appender->new( > >> "Log::Dispatch::File", > >> filename => > $main_logpath, > >> mode => "append", > >> name > >> =>$current_appender_name, > >> level=>$INFO > >> ); > >> > >> I'm doing this, but it doesn't seem to change the level of > initialisation. > >> Am I doing something wrong? > > > >I'd recommend using a Log4perl configuration file and the file > >appender that comes with Log::Log4perl: > > > >use Log::Log4perl qw(:easy); > > > >my $conf = q{ > >log4perl.category = DEBUG, Logfile > >log4perl.appender.Logfile = Log::Log4perl::Appender::File > >log4perl.appender.Logfile.mode = append > >log4perl.appender.Logfile.filename = /tmp/test.log > >log4perl.appender.Logfile.layout = Log::Log4perl::Layout::PatternLayout > >log4perl.appender.Logfile.layout.ConversionPattern = %d %F{1} %L> %m%n > >}; > > > >Log::Log4perl->init(\$conf); > >DEBUG "Hey there!"; > > > >If you really need to use Log::Dispatch::File and the L4p API, here's > >what I think you had in mind: > > > >use Log::Log4perl qw(get_logger :levels); > > > >my $logger = get_logger(""); > >my $appender = Log::Log4perl::Appender->new( > >"Log::Dispatch::File", > >filename => "woot.txt", > >mode => "append", > >name => "quack", > >min_level => "debug", > >); > >$logger->add_appender($appender); > > > >$logger->debug("waaa!"); > > > >-- Mike > > > >Mike Schilli > >m...@pe... > > > |