From: Bill M. <mo...@ha...> - 2008-05-13 18:12:27
|
I inherited an existing Log4perl configuration, and I think I'm missing some key point. The config file starts out: log4perl.rootLogger = INFO, syslogAppender, screenAppender >From the examples I've seen and the ::Config docs I thought it should be "log4perl.logger" not "log4perl.rootLogger". Yet, logging is working as expected. So, I'm curious about the difference. In ::Config it also give these examples: log4perl.logger.Bar.Twix = DEBUG, A1 log4perl.category.Bar.Twix = WARN, Screen Why is it "category" instead of "logger"? Finally, for a config like this in the example, what would be the perl code equivalent if not using a config file? log4perl.logger.Bar.Twix = DEBUG, A1 log4perl.appender.A1=Log::Log4perl::Appender::File log4perl.appender.A1.filename=test.log log4perl.appender.A1.mode=append log4perl.appender.A1.layout = \ Log::Log4perl::Layout::PatternLayout log4perl.appender.A1.layout.ConversionPattern = %d %m %n Like this? use Log::Log4perl qw(:levels); use Log::Log4perl::Appender::File; my $appender = Log::Log4perl::Appender::File->new( filename => 'test.log', mode => 'append', layout => Log::Log4perl::Layout::PatternLayout->new( '%d %m %n'), ); my $logger = Log::Log4perl->get_logger( 'Bar::Twix' ); $logger->level( $DEBUG ); $logger->add_appender( $appender ); -- Bill Moseley mo...@ha... |
From: Mike S. <m...@pe...> - 2008-05-16 06:01:55
|
On Tue, 13 May 2008, Bill Moseley wrote: > I inherited an existing Log4perl configuration, and I think I'm > missing some key point. Wow, I had no idea we're so old that you could inherit a log4perl configuration, but I guess time goes by :). > The config file starts out: > log4perl.rootLogger = INFO, syslogAppender, screenAppender > >From the examples I've seen and the ::Config docs I thought it should > be "log4perl.logger" not "log4perl.rootLogger". log4perl.logger with no category and log4perl.rootLogger are actually synonymous. log4perl.logger.foo.bar (with category foo.bar) needs to be 'logger', not rootLogger, obviously. > In ::Config it also give these examples: > log4perl.logger.Bar.Twix = DEBUG, A1 > log4perl.category.Bar.Twix = WARN, Screen > Why is it "category" instead of "logger"? That's an issue we inherited from Log4j. They started out naming categories "categories", then all of a sudden they called them loggers. I personally prefer the term 'category'. So, 'category' and 'logger' in a log4perl config file are synonymous. Yeah, confusing, I know :). > Finally, for a config like this in the example, what would > be the perl code equivalent if not using a config file? > > log4perl.logger.Bar.Twix = DEBUG, A1 > log4perl.appender.A1=Log::Log4perl::Appender::File > log4perl.appender.A1.filename=test.log > log4perl.appender.A1.mode=append > log4perl.appender.A1.layout = \ > Log::Log4perl::Layout::PatternLayout > log4perl.appender.A1.layout.ConversionPattern = %d %m %n > > > Like this? > > use Log::Log4perl qw(:levels); > use Log::Log4perl::Appender::File; > > my $appender = Log::Log4perl::Appender::File->new( > filename => 'test.log', > mode => 'append', > layout => Log::Log4perl::Layout::PatternLayout->new( '%d %m %n'), > ); > > my $logger = Log::Log4perl->get_logger( 'Bar::Twix' ); > > $logger->level( $DEBUG ); > $logger->add_appender( $appender ); You need to call the appender's layout() method to set the layout, other than that, the code above looks ok to me at first glance. It's fairly unusual to use Perl code to init Log4perl, most of the time people either use easy_init() or init($conf_file). -- Mike Mike Schilli m...@pe... |
From: Bill M. <mo...@ha...> - 2008-05-19 20:47:43
|
On Thu, May 15, 2008 at 11:01:35PM -0700, Mike Schilli wrote: > > You need to call the appender's layout() method to set the layout, other > than that, the code above looks ok to me at first glance. It's fairly > unusual to use Perl code to init Log4perl, most of the time people > either use easy_init() or init($conf_file). The log4perl config is not that complex, but we do have a few appenders. The problem is the log4perl.conf file is part of the application (it's in subversion with the rest of the code). But, the application has to run in different environments (development, testing, staging, production) so we need slightly different configurations under each environment. So, I was looking at having a single log4perl config and then using environment-specific config files to alter the behavior. The log message pattern might be the same under each mode, but the destination file might be different or the "owner" of the file might be different, for example. I have a way to handle this right now, but it just means I need separate log4perl config files for each operating environment. So, I end up duplicating the config for the majority of the log4perl config. I can see it would be handy to have a base config file and then be able to "override" just parts of the config that are different. -- Bill Moseley mo...@ha... |
From: Kevin M. G. <cp...@go...> - 2008-05-20 05:08:22
|
> > But, the application has to > run in different environments (development, testing, staging, > production) so we need slightly different configurations under each > environment. > > So, I was looking at having a single log4perl config and then using > environment-specific config files to alter the behavior. The log > message pattern might be the same under each mode, but the > destination file might be different or the "owner" of the file might > be different, for example. > > I have a way to handle this right now, but it just means I need > separate log4perl config files for each operating environment. So, I > end up duplicating the config for the majority of the log4perl config. > Interesting. The way they've solved that problem where I work, for *all* config files, not just log4perl, is to start with a base config file in a template, and when the service is started up, munge the config file based on per-host values. Something like this: ---------------------- # the config file looks like this log4perl.appender.file.filename = {$logfile} log4perl.appender.file.owner = {$owner} ----------------------- # the per-host values are set up somewhere like this $hosts = { QA => { logfile => '/var/log/qa.out', owner => 'bob the tester', }, PROD => { logfile => '/var/log/prod.out', owner => 'jerry the sysadmin', }, } # a Text::Template might be filled in like this $this_host = 'QA'; $munged_config = $template->fill_in(HASH => $hosts{$this_host}, ...); # and now you're ready to init Log::Log4perl::config(\$munged_config); |