Hi,
There is a bug 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 running. 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 =>
production.log.yyyymmdd)
- 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 attaching a patch for logger.rb that fixes 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 also a bug when rotating by size (shift_log_age) in the same environment (haven't tested or fixed
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!
- Guy.
|