I am newer to logrotate. when the configure comes to the property "dateformat",it seems that logrotate doesn't support strftime "%H" . here is the config:
{
daily
rotate 2
size 3M
missingok
notifempty
dateext
dateformat -%Y%m%d_%H:%M:%S
...
}
the rotated file format tend to look like : uwsgi_dev.log-20150630_%H:%M:%S, but I want the exact "hour minutes and seconds".
thanks
Support for %H was added in version 3.9.0. In earlier versions, logrotate did not support strftime "%H:
From the logrotate man page http://linux.die.net/man/8/logrotate
However, you can use
%s
in the dateformat string, which is the number of seconds since 1970-01-01. You can setdateformat -%Y%m%d-%s
. This will produce unique filenames every time the log is rotated, so you can rotate the file multiple times a day. Unfortunately, the%s
part will not be easy to read, but you can easily convert it back into a readable date withperl -e "print scalar(localtime(1451214849))"
.On some systems, the
date
program allows to do such conversion easily withdate -d @1451214849
(e.g. GNUdate
). On most systems (including e.g. Solarisdate
), you may have luck with syntax likedate -d "1970-01-01 + 1451214849 sec"
. Note that Busyboxdate
supports only the@
trick but not complex expressions of the second example.