Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure Logrotate with dateext and extension

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
    }
like image 262
Fdv Avatar asked Jul 10 '16 09:07

Fdv


People also ask

How do I logrotate var log messages?

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.

Where is the logrotate config file?

The main logrotate configuration file is located at /etc/logrotate. conf . The file contains the default parameters that logrotate uses when it rotates logs.

What is Sharedscripts in logrotate?

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.

How do I add a file to logrotate?

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


2 Answers

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
}
like image 73
Fdv Avatar answered Sep 22 '22 09:09

Fdv


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.

like image 31
jobevers Avatar answered Sep 21 '22 09:09

jobevers