What is the best way to enable log rotation on a Ruby on Rails production app?
Is it by using logrotate on the hosting server or is there a set of options to use when initializing logger from the app?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Option 1: syslog + logrotate
You can configure rails, to use the systems log tools.
An example in config/environments/production.rb.
That way, you log to syslog, and can use default logrotate tools to rotate the logs.
Option 2: normal Rails logs + logrotate
Another option is to simply configure logrotate to pick up the logs left by rails.
On Ubuntu and Debian that would be, for example, in a file called
/etc/logrotate.d/rails_example_com.As per suggestions below, in Rails it is advised to use
copytruncate, to avoid having to restart the Rails app.Edit: removed “sharedscripts/endscript” since they are not used here and cause problems according to comment. And removed
create 640 root admas per comment suggested.