Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 14 down vote accepted

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:


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

share|improve this answer
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. – Kolibert Jul 16 '09 at 5:17

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:

(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...)

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

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

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.

share|improve this answer
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 posting your answer, you agree to the privacy policy and terms of service.

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