Skip to content

Rotaing Magento Logs

Rotating logs can help prevent log files from becoming too large and unwieldy.

To setup Logrotate to automatically rotate Magento logs:

  1. Create a directory outside of the webroot to hold the config files:

    mkdir /srv/etc/
    mkdir /srv/etc/logrotate
    
  2. Create a logrotate.conf file with the following content:

    /srv/public_html/var/log/*.log {
        su magemojo magemojo 
        daily                
        missingok            
        rotate 30            
        compress  
        delaycompress 
        notifempty    
        olddir /srv/scaled/var/log/old/ 
    }
    
    • su magemojo magemojo — Ensures that permissions stay correct
    • daily – Run once a day at time set by cron job
    • missingok — Don't panic if empty
    • rotate 30 — Retain for 30 days
    • compress — Compress 2nd most recent file
    • delaycompress — Do not compress newest rotated log
    • notifempty — Do not rotate empty files
  3. Add a cron job to run once a day at the correct time:

    /usr/sbin/logrotate -s /srv/etc/logrotate/logrotate.state /srv/etc/logrotate/logrotate.conf