[grand-rapids-pm-list] Log::Dispatch:FileRotate

John DeYoung jdeyoung at gfs.com
Thu Nov 30 06:39:29 PST 2006


I have a callback method I use to dynamically return the logfile name I
want Log4perl to use  log4perl.appender.FileAppender.filename=sub{
return getLogFileName(); }.

The method, defined in main:: is sub getLogFileName { return
$logFileName; }

This works just fine when I'm using, Log::Log4perl::Appender::File.

However, I'd like to switch to Log::Dispatch::FileRotate, to leverage
the date rotation.

Unfortunately, using the callback method doesn't seem to work.  I
haven't changed the text of the method and my rotator definition is as
follows:

	log4perl.appender.FileRotator=Log::Dispatch::FileRotate
	log4perl.appender.FileRotator.filename=sub { return
getLogFileName(); }
	log4perl.appender.FileRotator.min_level=info
	log4perl.appender.FileRotator.mode=append
	log4perl.appender.FileRotator.max=2
	log4perl.appender.FileRotator.TZ=GMT
	log4perl.appender.FileRotator.DatePattern=0:0:0:1:0:0:0
	log4perl.appender.FileRotator.layout=Log::Log4perl::Layout::PatternLayout
	log4perl.appender.FileRotator.layout.ConversionPattern=${default_layout_format}

When my script is run, the correct log file is created but, nothing is
written to it.

To find out whether the problem is in the config file or the callback
method, I changed the callback method to the following, 
sub getLogFileName {
  my $string = "c:\winnt\temp\util\util.log";
  return $string;
}
This works just fine.  The log file is created and output written to
it, as expected.  My problem is that I want to build the log file name
dynamically, depending on which environment and other factors.  I've
tried several different ways to pass the dynamic text "quoted", to no
avail.

The closest I've come is to have a "CODEhhhhhh" reference passed to
config but, I'm not sure how to dereference that into a string.

Any advice would be appreciated.







More information about the grand-rapids-pm-list mailing list