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.
Handling Active Log File. In the default behavior, the rotation process beings by logrotate renaming the active log file into a different name. Then, it creates a new log file with the same name. Finally, it invokes other logic such as compress and mail to complete the rotation process.
Normally, logrotate is run as a daily cron job. It will not modify a log more than once in one day unless the criterion for that log is based on the log's size and logrotate is being run more than once each day, or unless the -f or --force option is used. Any number of config files may be given on the command line.
If you want to force Logrotate to rotate the log file when it otherwise would not have, use the --force flag: logrotate /home/sammy/logrotate. conf --state /home/sammy/logrotate-state --verbose --force.
If you want to rotate /var/log/syslog it needs to be listed in a logrotate config file somewhere, and you just run logrotate . If it rotated recently, then logrotate -f to force it to do it again. So, you need that in a file, normally either /etc/logrotate. conf or as a file snippet in /etc/logrotate.
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?
logrotate is working only once a day , So it's not checking your file size all the time.
if you want an effective way to keep the size lower , you should use a cron job like
for example , force the rotate every hour in your crontab
0 * * * * logrotate <my conf here>
and your logs will be , if needed, rotated every hour. I had such problem in my free-tier aws server , as the size exceed rapidly and i didn't have enough disk space to wait 24 hours for a rotate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With