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
Logrotate does not support hourly schedule, but this is an easy task to accomplish. Create separate directory to store hourly logrotate configuration files. Create main logrotate configuration file that will read configuration files from designated directory.
You can check the settings of logrotate , usually in /etc/logrotate. conf . Modern distros have a specific logrotate configuration file in the /etc/logrotate. d directory.
Default Value. maxage days. Sets the number of days that a log file is kept. At the end of this period, the log file is deleted.
Add an entry for your log fileAt the end of logrotate. conf, add the full path to your log file followed by open and close curly brackets. There are many options you can add like the frequency to rotate "daily/weekly/monthly" and the number of rotations to keep "rotate 2/rotate 3".
Support for %H
was added in version 3.9.0, for %M
and %S
- 3.9.2 In earlier versions, logrotate did not support strftime "%H:
dateformat format_string: Specify the extension for dateext using the notation similar to strftime(3) function. Only %Y %m %d and %s specifiers are allowed.
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 set dateformat -%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 with perl -e "print scalar(localtime(1451214849))"
.
On some systems, the date
program allows to do such conversion easily with date -d @1451214849
(e.g. GNU date
). On most systems (including e.g. Solaris date
), you may have luck with syntax like date -d "1970-01-01 + 1451214849 sec"
. Note that Busybox date
supports only the @
trick but not complex expressions of the second example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With