Logrotate does not auto rotate when based on log size

One picture One · Jun 30, 2011 · Viewed 11k times · Source

I have a custom application (myApp) which is writing logs to the file '/var/log/myApp'. I can see the logs being written and it works fine. Now I am trying to setup logrotate for this file and for this I have created a config file '/etc/logrotate.d/myApp', the contents of which are -

/var/log/myApp {
   missingok
   size +10k
   start 0
   nocompress
   create 0600 root root
   rotate 10
   postrotate
     /etc/init.d/rsyslog restart > /dev/null 2>&1 || true
   endscript
}

Now if i do a logrotate -dv /etc/logrotate.d/myApp I don't see any errors as such and when logrotate -f /etc/logrotate.d/myApp is executed i.e., a forceful logrotate the log is rotated. But when the log file size exceeds 10k the log is not automatically rotated. Any help would be appreciated.

Answer

FuriousGeorge picture FuriousGeorge · Feb 1, 2012

logrotate rotates the logs specified in /etc/logrotate.d/ according to the time interval configured in /etc/logrotate.conf. On some distros, the default value is a week. You can override that time interval in your specific config using e.g. 'daily' in your config file.

Log files will not be rotated until logrotate has known about the files for at least as long as the time specified. I assume that you waited this long and/or modified the conf file?