shree has asked for the wisdom of the Perl Monks concerning the following question:

Hi I have my log4 Perl configuration file as below, Here I have done the changes to conf file to create the new log file every day midnight 12:00 automatically. But still it's writing to the same existing file even after the date get change, instead of creating the new log file with current date.

Here all my Perl scripts which creates the logs are running in daemon mode and it runs 24*7. Here I have the Log::Dispatch::FileRotate with Version 1.19

Can anyone help me on this?
[log4perl] log4perl.logger=WARN,Logfile log4perl.appender.Logfile = Log::Dispatch::FileRotate log4perl.appender.Logfile.filename = sub { return get_log(); } log4perl.appender.Logfile.mode = append log4perl.appender.Logfile.max = 2 log4perl.appender.Logfile.DatePattern = yyyy-MM-dd log4perl.appender.Logfile.layout = Log::Log4perl::Layout::PatternLayou +t log4perl.appender.Logfile.layout.ConversionPattern = %d %p> %m%n log4perl.appender.Screen = Log::Log4perl::Appender::Screen log4perl.appender.Screen.stderr = 0 log4perl.appender.Screen.layout = Log::Log4perl::Layout::PatternLayout log4perl.appender.Screen.layout.ConversionPattern = %d %p> %m%n [Modules level setup]
  • Comment on How can I roll over my log files automatically at midnight with Log4 Perl?
  • Download Code

Replies are listed 'Best First'.
Re: How can I roll over my log files automatically at midnight with Log4 Perl?
by happy.barney (Friar) on Nov 29, 2010 at 09:29 UTC
    i'm using Log::Dispatch::File::Rolling
    log4perl.appender.LogFile = Log::Dispatch::File::Rolling log4perl.appender.LogFile.filename = ${dir}/${name}.%d{yyyy-MM-dd}.log
Re: How can I roll over my log files automatically at midnight with Log4 Perl?
by chrestomanci (Priest) on Nov 29, 2010 at 09:38 UTC

    There is a TZ property that you can set on the Log::Dispatch::FileRotate appender. You need to set it so that it knows when local midnight is.

    You profile says you are in Bangalore, and Google suggests that your local timezone is IST, so you probably want to add a line like this to your log4perl config:

    log4perl.appender.Logfile.TZ=IST