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.

Krystian Cybulski
  • 495
  • 3
  • 6
  • 13

3 Answers3

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.

Juliano
  • 5,402
  • 27
  • 28
  • 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 05: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...)

Cos
  • 251
  • 1
  • 3
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.

theotherreceive
  • 8,235
  • 1
  • 30
  • 44
  • 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) – Stéphane B. Sep 11 '15 at 12:05