Logrotat does not rotate automatically if, based on the size of the log

I have my own application (myApp) that writes logs to the file '/ var / log / myApp'. I see how the logs are written and everything works fine. Now I'm trying to install logrotate for this file, and for this I created a configuration 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 do not see any errors as such, and when logrotate -f /etc/logrotate.d/myApp is executed, i.e. forced logrotate, the log rotates. But when the log file size exceeds 10k, the log will not be automatically rotated. Any help would be appreciated.

+7
source share
2 answers

logrotate rotates the logs specified in /etc/logrotate.d/ according to the time interval configured in /etc/logrotate.conf . On some distributions, the default value is week. You can override this time interval in your specific configuration, for example, "daily" in your configuration file.

Log files will not rotate until logrotate knows about the files for at least as many as specified. I assume that you have been waiting and / or modifying the conf file for a long time?

+3
source

logrotate only works once a day, so it does not check the size of your file all the time.

if you need an efficient way to reduce the size you should use a cron job like

for example force to rotate every hour in your crontab

 0 * * * * logrotate <my conf here> 

and your magazines will be rotated every hour if necessary. I had such a problem on my aws server since the size was higher and I did not have enough disk space to wait 24 hours to rotate

+1
source

All Articles