7

Right now, logrotate renames old log files to access.log.1.gz, access.log.2.gz, etc. I would prefer if it named them access.log.20090714.gz, access.log.20090715.gz, etc - one for each day.

I cannot find any option of specifying a filename pattern for the old log files. Do you know how to do this?

BTW, this is for rotating lighttpd log files, if that matters.

14

In /etc/logrotate.conf or /etc/logrotate.d/lighttpd, or the proper file if anywhere else, add dateext to the stanza you want to apply date suffixes.

More information from logrotate man page:

dateext

Archive old versions of log files adding a daily extension like YYYYMMDD instead of simply adding a number.

  • While the other answers may also yield the results I need, this one is the simplest. Even though it does not provide the same exact file name I initially desired, it does accomplish the task I needed. Thank you. – Krystian Cybulski Jul 16 '09 at 5:17
2

Use cronolog - it'll write logfiles with the correct filenames in the first place (eg. I generally have my webservers write logfiles as YYYY/MM/DD/access, or YYYY/MM/DD/error, and so forth). More details on configuring cronolog with lighttpd are here: http://redmine.lighttpd.net/projects/1/wiki/MigratingFromApache

(while that page mentions that server.errorlog can't be run through cronolog, there appears to be a bug report for this that has been marked as "fixed" - unfortunately i can't post more than one URL at a time, since I'm a "new" user on serverfault...)

  • Cool. We use cronolog on apache, but I didn't think it worked on lighttpd. – theotherreceive Jul 16 '09 at 0:56
0

I don't think that lighttpd or logrotate can do this by themselves. I see two options to achieve this:

Do your own scripting directly after logrotate, like at the end of it's cronjob. Something like:

if [ -f /var/log/lighttpd/access.log.1.gz ]; then`
    mv /var/log/lighttpd/access.log.1.gz /var/log/lighttpd/access.log.$date.gz
fi

Or, syslog-ng can build log files by date, and lighttpd can send logs to syslog rather than writing them itself.

# syslog-ng.conf
destination df_lighttpd { file("/var/log/lighttpd/$YEAR$MONTH$DAY.log"); };
filter f_lighttpd { program("lighttpd"); };
log { source(s_all);  filter(f_lighttpd); destination(df_lighttpd); };

and set accesslog.use-syslog & server.errorlog-use-syslog in the lighttpd conf.


Edit: Cronolog is simpler and/or than either of my suggestions, I'd go with that if it works for you.

  • date environment variable doesn't exist, you should replace $date by date +"%Y%m%d" (don't forget backquote before and after this command that are hidden) – STB Land Sep 11 '15 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.