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

Hi I have the my log4 Perl configuration file as below, Here I have done the changes to conf file to create the new log file every day automatically. But still it's writing to the same existing file even the date get change. So please let me know anything else conf changes i need to do get created the new log file every day when date got changed



[log4perl] log4perl.logger=WARN,Logfile #log4perl.threshold = OFF##switch off all loggers #log4perl.appender.Logfile = Log::Log4perl::Appender::File log4perl.appender.Logfile = Log::Dispatch::FileRotate log4perl.appender.Logfile.filename = sub { return get_log(); } #log4perl.appender.Logfile.recreate = 1 log4perl.appender.Logfile.mode = append #log4perl.appender.Logfile.size = 15728640 ##15MB log4perl.appender.Logfile.max = 2 log4perl.appender.Logfile.DatePattern = yyyy-MM-dd #log4perl.appender.Logfile.additivity =0 log4perl.appender.Logfile.layout = Log::Log4perl::Layout::PatternLayou +t log4perl.appender.Logfile.layout.ConversionPattern = %d %p> %m%n #log4perl.appender.Logfile.layout.ConversionPattern = %d %p> %F{1}:%L +%M - %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]
.
.
.
.
.
.
.
.
.

Replies are listed 'Best First'.
Re: How can I roll over my logfiles automatically at midnight?
by Khen1950fx (Canon) on Nov 12, 2010 at 12:45 UTC
    Maybe this can help.
    [log4perl] log4perl.logger = WARN,Logfile log4perl.appender.Logfile = Log::Dispatch::FileRotate log4perl.appender.Logfile.filename = test.log log4perl.appender.Logfile.max = 2 log4perl.appender.Logfile.DatePattern = yyyy-MM-dd log4perl.appender.Logfile.TZ = PST log4perl.appender.Logfile.layout =\ Log::Log4perl::Layout::PatternLayout log4perl.appender.Logfile.layout.ConversionPattern = %d %m %n log4perl.logger = WARN, Screen 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 %m %n [Modules level setup]
Re: How can I roll over my logfiles automatically at midnight?
by JavaFan (Canon) on Nov 12, 2010 at 11:50 UTC
    I would use logrotate, which came with my OS. Just stick the appropriate entry in /etc/logrotate.conf.
Re: How can I roll over my logfiles automatically at midnight?
by Illuminatus (Curate) on Nov 12, 2010 at 12:47 UTC
    To elaborate on what JavaFan said, log4perl, to my knowledge, has no built-in mechanism for actually rotating files. While you may have set-up the log4perl config to handle rotation, you will need another script or utility to actually perform the file movement. logrotate is one such utility. You could also write your own shell/perl script to do what you want, and set-up cron directly to run it.

    fnord

Re: How can I roll over my logfiles automatically at midnight?
by FalseVinylShrub (Chaplain) on Nov 12, 2010 at 12:42 UTC

    Hi

    Looks like that's what your config file should be doing already. I'm sure I've done the same thing before.

    It might be easier for someone to help you if you removed the irrelevant commented-out lines ;-)

    FalseVinylShrub

    Disclaimer: Please review and test code, and use at your own risk... If I answer a question, I would like to hear if and how you solved your problem.