开发者

Rolling logs in unicorn

开发者 https://www.devze.com 2023-04-12 21:01 出处:网络
Whats the best way to roll logs on a daily basis using Rails 2.3.5 and Unicorn. The general log rolling params to the Logger class don\'t work if there are multiple instances of Unicorn running as all

Whats the best way to roll logs on a daily basis using Rails 2.3.5 and Unicorn. The general log rolling params to the Logger class don't work if there are multiple instances of Unicorn running as all the workers will not get their file handles reset.

On the Unicorn pages I saw USR1 being suggested. A few clarifications on it:

  • Does this cause the log file to be rolled with a new name and a fresh log file gets opened?
  • I still have the issues of renaming the existing log开发者_如何学运维s to the next version whenever the rollover happens.

Do most folks use the std Unix logrotate to achieve this?


You might be doing it already but first you should make each worker log to a different file (to not get mixed logs). I think (not completely sure) Rails 2.3 uses an old version of BufferedLogger for logging that has some flushing capabilities that avoid this log separation. But as of Rails 3.2 the flushing is done OS level so cannot rely on the logs being printed properly on the same file.

Look here for solutions on that:

  • how to make rails+unicorn logger thread safe?
  • How to make each unicorn worker of my Rails application log to a different file?

On the main question, rolling has been also disabled for newer Rails (3.2+) so I suggest using logrotate; you never know when you are going to upgrade.

logrotate

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号