Why does rails crash when rotating logs? What is the proper way to rotate logs in rails?

StackOverflow https://stackoverflow.com/questions/9102043

  •  21-04-2021
  •  | 
  •  

문제

I did not want to go through the headache of setting up 4 node-servers with 3 applications each by using logrotate for UNIX.

So I decided to setup my rails applications with the following inside environment.rb:

  log_path = "#{Rails.root}/log/#{ENV['RAILS_ENV']}.log"
  shift_age = 'weekly' # you can either 1) specify 2 params 50, 1024bytes OR 2) specify 1 param 'daily | weekly | monthly'
  config.logger = Logger.new(log_path, shift_age)

However, this caused the rails application to break once the files were rolled over.

I am wondering, what is the best way to rotate logs with rails applications? Is it logrotate? Thanks.

도움이 되었습니까?

해결책

This happens because one process is trying to rotate the log file at the same time that the another process is trying to rotate it, a race condition occurs, and the server stops responding to requests, as a Fatal Exception is raise

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top