How to configure log rotation with logrotate
Updated 7/20/2026
Without rotation, a log file can reach gigabytes and fill the disk. logrotate solves this by automatically archiving and deleting old logs.
It is already installed
Most distributions ship logrotate preinstalled, with rules for system services. You configure it for your own applications.
Example configuration
Create /etc/logrotate.d/my-app:
/var/log/my-app/*.log {
daily
rotate 14
compress
delaycompress
missingok
notifempty
copytruncate
}
What it means
- daily: rotate daily.
- rotate 14: keep 14 archives (two weeks).
- compress: gzip archives to save space.
- copytruncate: useful for apps that keep the file open.
Test
logrotate -d /etc/logrotate.d/my-app # simulate
logrotate -f /etc/logrotate.d/my-app # force now
Combine with space monitoring, see disk monitoring, so a full disk never surprises you.
Put this guide into practice on your own VPS
EU cloud servers, billed hourly, ready in minutes, with one-click installs for dozens of apps.
See pricingRelated tutorials
How to monitor database performance
See slow queries, connections and database usage, to keep it fast.
Updated 7/20/2026Monitoring & loggingHow to monitor disk space and avoid running out
A full disk stops services and corrupts data. Here is how to track space and get alerts in time.
Updated 7/20/2026Monitoring & loggingHow to monitor a website and SSL expiry
Do not let your site go down or your SSL certificate expire without knowing. Here is how to track them automatically.
Updated 7/20/2026