Docs / Monitoring & Logging / How to Set Up Log Rotation on Linux

How to Set Up Log Rotation on Linux

By Admin · Feb 25, 2026 · Updated Apr 23, 2026 · 82 views · 1 min read

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

Was this article helpful?