There seems to be a bug (or just unexpected behavior…) in logger.rb’s
rotation that causes it to either misbehave or fail the application
when running in a multi-process environment - specifically Rails.
I have Ruby on Rails under FastCGI, with multiple dispatch.fcgi
processes alive. My logger is configured for daily rotation. The
problematic scenario is this:
- Come midnight, the first Rails process that happens to get a
request renames the log file (production.log =>
- Subsequently, the remaining Rails processes attempt to rename the
file as well, but fail completely because production.log.yyyymmdd
already exists. Logger raises an exception, and users receive “500
Internal Server Error”.
- Until all Rails processes are restarted, only the first one will
work and all the rest will continue to fail violently.
I’m including a patch for logger.rb that fixes Logger#shift_log_period
so that it doesn’t fail violently if log.yyyymmdd already exists, but
rather just reopens the logfile and keeps on working.
Note there is probably a bug when rotating by size
(Logger#shift_log_age) in the same environment (haven’t tested it, but
reading the code seems to indicate it will happen). Although nothing
will fail violently, each Rails process, ignorant of its peers, will
rotate the logs and the end result will be multiple rotations!