Using logrotate to manage Magento 2 logs

For Dedicated and VPS customers only. Not available for shared hosting.

Logrotate is a  command line utility available on Linux which can make managing Magento log files in var/log to keep them small and to keep a weeks worth of backups.
it is also extremely easy to implement on dedicated servers and VPS. At present you can't do so on shared hosting.

First, create a file in /etc/logrotate.d/magento-domain.com with the following content (replacing username and domain.com as necessary),

/home/username/public_html/var/log/*.log {
  daily
  rotate 7
  missingok
  compress
  copytruncate
  notifempty
  create 660 username username
}

 

You may wish to change some fo the settings as below...

SettingUse
/home/username/public_html/var/log/*.log Path to the log files
daily Rotation frequency (daily|weekly|monthly|yearly)
rotate 7 How many rotations should be kept
  • 0 Users Found This Useful
Was this answer helpful?