When locally debugging a production issue today I kept getting this message when starting the server:
Rails Error: Unable to access log file. Please ensure that /path/to/rails/app/log/production.log exists and is chmod 0666. The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.

Despite the fact that the file was indeed present and accounted for (permissions-wise — not exactly 0666 but perms matched other log files):
-rw-r--r--   1 brad  admin        0 Jun 26 13:07 production.log

As it turns out, there is a “bug” in Rail’s logger configuration code such that if an exception is thrown during configuring the logger it just tells you it couldn’t get to the file. This isn’t so much a bug as just a poorly-worded error message.

The Fix

The root cause of my issue was that in configs/environments/production.rb I was configuring logging like so (legacy Rails way, apparently):
config.log_level = Logger::WARN

When I should be configuring it thusly:
config.log_level = :warn

After changing configuration, everything worked just dandy.

How was this bug originally manifested?

Interestingly, I originally started looking in to this because (surprise surprise) logging wasn’t working in production! This fixed the issue.

About these ads