How to configure Logrotate with dateext and extension
Asked Answered
C

2

5

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
    }
Checkmate answered 10/7, 2016 at 9:21 Comment(0)
C
12

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
}
Checkmate answered 12/7, 2016 at 9:29 Comment(4)
I got postgresql.2018-08-02.log after applying the same idea. It's not quite the desired postgresql-2018-08-02.log, but the approach is valid.Unblessed
What file name and extension you get by this setting?Integrity
I used dateext dateformat -%Y-%m-%d. addextension old. I got b-2022-07-21.oldFeune
It seems extension is not necessary: https://mcmap.net/q/676091/-logrotate-suffix-dateext-rotatePtyalism
G
3

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.

Gasparo answered 26/1, 2020 at 14:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.