brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: delaycompress leaves the newest rotated logs uncompressed for one round

Logs
~/tips/tip-logs-logrotate-delaycompress

rotate 14

Keep yesterday's file readable and avoid compressing a file still in use.

With compress alone, logrotate gzips the old file right away. That is a problem if the program still has it open and keeps writing for a while.

Add delaycompress next to it:

/var/log/myapp/*.log {
    daily
    rotate 14
    compress
    delaycompress
    missingok
    notifempty
}

Now the most recently rotated file stays as plain text, for example app.log.1, and it is compressed at the next rotation. Older ones are .gz as before.

There is a bonus for troubleshooting. Yesterday’s log can be read and searched with ordinary grep and less, which is the file I reach for most after the current one.

The man page suggests it for programs that cannot be told to close their log file straight away. A web server that is reloaded by a postrotate script can still have old workers finishing requests, and this gives them time.

Check your syntax without rotating anything:

sudo logrotate -d /etc/logrotate.d/myapp

The option does nothing without compress. It also does not help a program that never reopens its file at all; that one keeps writing into the renamed file until you restart it. And you use a bit more disk, which matters if a single day of logs is huge.

Further reading: logrotate man page

More Logs tips rotate 4 sort -m app.log worker.log | less sed -E 's/[0-9]+/N/g' app.log | sort | uniq -c | sort -rn | head -n 15 awk '$1 >= "2026-11-30T02:00" && $1 < "2026-11-30T03:00"' app.log logger: All Logs tips (9) All topics

Link