2

How do I setup logrotate to rotate openerp-server.log into openerp-server-YY-MM-DD.log?

  • 2
    This question isn't too broad, it's about a specific feature of logrotate. – Bratchley Feb 6 '15 at 13:59
  • i have to rotate openerp-server.log to openerp-server-YY-MM-DD.log..eg:it should be look like this openerp-server-2015-02-06.log – user102138 Feb 6 '15 at 14:56
  • do you got me what i have said before comment. – user102138 Feb 6 '15 at 14:59
  • @user102138 I think he's asking for your current logrotate.conf settings for this log file. – Bratchley Feb 6 '15 at 15:00
  • after logfile rotated it should be appear like this openerp-server-2015-02-06.log – user102138 Feb 6 '15 at 15:02
3

Geez someone has really gone on a tear voting to close questions without even attempting to ask for clarification.

To answer your question, though you want to look at dateext. For example:

/var/log/yum.log {
    missingok
    notifempty
    size 30k
    yearly
    create 0600 root root
    dateext
}

Which results in:

[root@xxx01 ~]# ll /var/log/yum.log*
-rw------- 1 root root    0 Feb  6 08:39 /var/log/yum.log
-rw------- 1 root root 4060 Jan  1  2014 /var/log/yum.log-20140101.gz
-rw------- 1 root root 1383 Jan  1 03:35 /var/log/yum.log-20150101.gz

If you want to change the date format you can use the dateformat directive.

0
/var/log/odoo/odoo-server.log
 {
        weekly
        rotate 5
        copytruncate
        missingok
        ifempty
        postrotate
                /etc/init.d/odoo-server force-reload > /dev/null
                cat /var/log/odoo/odoo-server.log >> /var/log/odoo/odoo-server-$(date +%Y-%m-%d).log
        endscript
 }
  • This won't work as well because you're actually copying a more or less empty log (since the log is truncated as part of the rotate) and the actual log is still going to be named odoo-server.log.1 odoo-server.log.2 etc etc. This is why the dateext is used for what you're wanting. You also probably want to change ifempty to be notifempty otherwise you'll have even more empty logs. – Bratchley Feb 9 '15 at 21:30
0
/var/log/odoo/odoo-server.log {
daily
copytruncate
create 644 harmony-4 harmony-4
dateext
dateformat -%Y-%m-%d
rotate 5
extension .log
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.