Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

logging - Ruby on Rails production log rotation

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 initialising logger from the app?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Option 1: syslog + logrotate

You can configure rails, to use the systems log tools.

An example in config/environments/production.rb.

# Use a different logger for distributed setups
config.logger = SyslogLogger.new

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.

/path/to/rails.example.com/tmp/log/*.log {
    weekly
    missingok
    rotate 52
    compress
    delaycompress
    notifempty
    copytruncate
}

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 adm as per comment suggested.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...