Magento’s var/log folder can quietly grow to many gigabytes. Nothing breaks until the disk fills. Then Magento can no longer write sessions or cache files, and every page starts failing at once with no warning.

Find which log is growing

du -sh var/log
ls -lhS var/log/ | head

The biggest file tells you what is wrong:

  • debug.log: debug logging is switched on in a live store.
  • exception.log or system.log: an error is repeating, often on every request. That is a real fault to fix.
  • cron.log: Magento writes a few lines for every cron job, every minute, so it grows steadily even when everything is healthy.
  • An extension’s own log: some extensions log every API call or request.

See what is repeating

tail -50 var/log/exception.log
grep -oE '\] main\.[A-Z]+: .{0,80}' var/log/system.log | sort | uniq -c | sort -rn | head

Clear the logs safely

Empty files in place instead of deleting them, so processes that have them open keep working:

truncate -s 0 var/log/debug.log

Disk space comes back immediately, with no downtime.

Stop them refilling

Turn off debug logging:

bin/magento config:set dev/debug/debug_logging 0
bin/magento cache:flush

Fix the repeating exception, because it is usually a real bug affecting customers. Then add log rotation so the size stays under control automatically. Create /etc/logrotate.d/magento:

/var/www/magento/var/log/*.log {
    weekly
    rotate 4
    compress
    missingok
    notifempty
    copytruncate
}

Also check var/report, where Magento saves a file for every error page a visitor sees. Thousands of files there mean customers are seeing errors.

Catch it automatically

MageMonitor checks for this every few minutes as part of its performance checks, and alerts you by email, Slack or webhook the moment it appears, with the exact commands to fix it. See MageMonitor for Magento 2.

Related fixes