3

What is the best way to rotate Ruby on Rails log files daily?

I saw posts in the past. They recommended using logrotate and enable copytruncate option to avoid restarting Rails.

However, logs are lost at small time slice between copying the file and truncating it.

My project requirement does not lose logs, so we chose cronolog with ruby's stdlib Logger. The code like the following:

config.logger = Logger.new(IO.popen("/usr/sbin/cronolog #{config.paths['log'].first}.%Y%m%d", "w"))

It's mostly works correctly, but logs are mixed when logging data size more than PIPE_BUF that because using PIPE.

So what is recommended way to rotate logs in such situation?

4

0 回答 0