Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

3 Answers 3

up vote 12 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:

dateext

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

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

share|improve this answer

Your Answer

 
discard

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.