I tried to configure logrotate to keep the date and the extension of the log being rotated:
With the current configuration, the file:
/var/www/redmine/log/production.log
Is logrotated in :
/var/www/redmine/log/production.-20160710log
I was expecting :
/var/www/redmine/log/production-20160710.log
Please see below an extract vof the logrotate configuration file :
cat /etc/logrotate.d/redmine
rotate 4
weekly
missingok
notifempty
compress
delaycompress
sharedscripts
dateext
/var/www/redmine/log/production.log
{
create 755 www-data www-data
extension log
}
The command /usr/bin/chattr -a is run to remove the append-only attribute from /var/log/messages. The endscript command marks the end of the prerotate portion of this script. The next line, postrotate, specifies the following commands are to be run on /var/log/messages after the file has been rotated by logrotate.
The main logrotate configuration file is located at /etc/logrotate. conf . The file contains the default parameters that logrotate uses when it rotates logs.
The sharedscripts means that the postrotate script will only be run once (after the old logs have been compressed), not once for each log which is rotated. Note that the double quotes around the first filename at the beginning of this section allows logrotate to rotate logs with spaces in the name.
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".
I Got it !
Just added the "dateformat %Y-%m-%d." Including a "." in the format
rotate 4 weekly missingok notifempty compress delaycompress sharedscripts dateext dateformat %Y-%m-%d. /var/www/redmine/log/production.log { create 755 www-data www-data extension log }
To get production-20160710.log
instead of production.2016-07-10.log
you can do:
dateext
dateformat -%Y%m%d
/var/www/redmine/log/production.log
{
extension .log
}
The dateformat
can actually be left out as that is the default.
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