Last Updated: February 25, 2016
·
1.464K
· jan0sch

Rotating rails application log files

To prevent the log files of a rails application to grow without limit you should setup log rotation. There are several ways to do this. Here is a simple solution using logrotate.

Create a config file (usually something like /etc/logrotate.d/my-app):

/full/path/to/my_rails_app/log/*.log {
   weekly
   missingok
   rotate 52
   compress
   delaycompress
   notifempty
   copytruncate
}

This will rotate logs on a weekly basis and keep them for a year. Notice that the copytruncate option is essential to prevent your rails app from having to reboot.