Context
I am required to use a poorly designed java application that logs A LOT of information while it is running. Under standard usage, it will create 100s of MB of logs per hour.
I don't need historical logs and it currently seems that the logrotate utility can't keep up with it as it doesn't run frequently enough. The application is closed source and rotates it's own logs at around 36MB.
My Linux distribution is RHEL7.
Question
I'd like to reduce wasted space by compressing and rotating the logs.
- As the app already splits out the logs into new files, is it possible to automatically compress newly created files in a directory?
- Is it possible to automatically delete all files in the format of assessor-cli.X.log where X is a digit greater than... say 5 (i.e. keep only the 5 most recent logs).
Here is my attempt at a logrotate file:
# cat /etc/logrotate.d/cis_assessor
/usr/share/foreman-proxy/Ansible/CIS/audit/Assessor-CLI-4.0.2/logs/assessor-cli.log {
missingok
notifempty
compress
rotate 5
size 30M
This logrotate job would need to catch the log between the size of 30MB and 36MB to actually come into effect which might only be a 10 second period. That's why I'm asking about the manual path of compressing and deleting files without logrotate.
logrotate
doesn't run frequently enough for your use case. It's possible to set up alogrotate
command with a custom state file and custom configuration file so that runs independently of the system'slogrotate
. At that point, it's just a normal command you can schedule with cron. – Haxiel Feb 12 '19 at 05:36