On Wed, 16 Jan 2008 [EMAIL PROTECTED] wrote:

> I am testing it and it looks like it is working OK.  I am wondering if
> it is possible to do what I want to with it.  I want, when the file
> rotate every day to change the file name to include the date in the
>
> But like I read in the documentation, the sub are executed only once
> at the time the config file is read. So the date in the file name is
> always the date when I start the program.

That's correct, only the appender or an external program can take care
of renaming the log file.

Log::Dispatch::FileRotate (which is not part of Log4perl but a 3rd party
module) renames log files as file.log.1, file.log.2, etc., but that's
not what you want.

Instead, I'd suggest you use an external rotator and let it take care of
the renaming issue. Make sure you read the gotchas regarding external
rotators, first:

    http://log4perl.sourceforge.net/d/Log/Log4perl/FAQ.html#2d0d0

Then I'd probably use a configuration like this:

  log4perl.category = WARN, Logfile
  log4perl.appender.Logfile          = Log::Log4perl::Appender::File
  log4perl.appender.Logfile.filename = test.log
  log4perl.appender.Logfile.recreate = 1
  log4perl.appender.Logfile.layout = Log::Log4perl::Layout::PatternLayout
  log4perl.appender.Logfile.layout.ConversionPattern = %d %F{1} %L> %m%n

and an external rotator that kicks in right after midnight every day as
a cronjob:

  01 00 * * * cd /my/logs; mv test.log test.log.`date +%F`

Because of the 'recreate' flag set in the Log4perl configuration,
Log4perl will notice when the file is missing (until it does notice, it will
keep writing to the moved file, which is fine if you hold off on
compressing it until the switch is made).

The Log::Log4perl::Appender::File documentation lists more details on
the 'recreate' flag.

Hope that helps!

-- Mike

Mike Schilli
[EMAIL PROTECTED]

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
log4perl-devel mailing list
log4perl-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/log4perl-devel

Reply via email to