Skip to content

Logrotate Magento Logs

In order to setup Logrotate to automatically rotate Magento logs, follow these steps:

  1. Create a directory outside of your webroot to hold the config files:
    mkdir /srv/etc/
    mkdir /srv/etc/logrotate

  2. A config file needs to be put in here. This can be created locally and then uploaded, or edited directly on the server.

  3. Set the Config up similar to this example:

/srv/public_html/var/log/*.log {
    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
    olddir /srv/scaled/var/log/old/    # Store rotated files in this directory, so that all logs can be rotated under one entry
}
  1. 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