Log rotation prevents log files from consuming all disk space.
Default Configuration
Logrotate runs daily via cron. Main config: /etc/logrotate.conf. App-specific configs: /etc/logrotate.d/.
Create a Custom Config
Create /etc/logrotate.d/myapp:
/var/log/myapp/*.log {\n daily\n rotate 14\n compress\n delaycompress\n missingok\n notifempty\n create 0644 www-data www-data\n postrotate\n systemctl reload myapp > /dev/null 2>&1 || true\n endscript\n}Test
logrotate -d /etc/logrotate.d/myapp # Dry run\nlogrotate -f /etc/logrotate.d/myapp # Force rotation