views:

1133

answers:

2

I get the following error when restarting my rails app. I've had this problem before, on another server with another app, but can't remember what the problem was, or how I solved it.

Rails Error: Unable to access log file. Please ensure that /apps/staging/releases/20090310162127/log/staging.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.

I'm deploying to a mongrel cluster with capistrano on Ubuntu.

When I do ls -l /apps/staging/releases/20090310162127/log/staging.log

the result is:

-rw-rw-rw- 1 me grp 51 Mar 10 16:07 /apps/staging/releases/20090310162127/log/staging.log

The log dir is a link to /apps/staging/shared/log.

What's going on?

A: 

Is Rails running as me? If not, what user is it running as? Is that user jail'ed? Does the user have traverse permissions for all components of /apps/staging/shared/log as well as all components of /apps/staging/releases/20090310162127/log?

vladr
Yes, it's running as "me", no idea what jail'ed means though. Yes, all the dir components are traversable. releases/20090310162127 is probably accessed through a link (called current).
Michiel de Mare
@Michiel, jailed means that / is remapped to a special directory for security reasons. Can you confirm that if you 'su - me' and 'touch /apps/staging/releases/20090310162127/log/staging.log' you do not get an error, correct?
vladr
Interesting - I should look into that. The error message was completely misleading though - nothing to do with the log file.
Michiel de Mare
+4  A: 

It turned out to be a subtle rails bug:

When an exception is raised in these two lines

logger = ActiveSupport::BufferedLogger.new(configuration.log_path)
logger.level = ActiveSupport::BufferedLogger.const_get(configuration.log_level.to_s.upcase)

rails assumes it can't find the log file. However, the actual error occurred in the second line: a NameError because the constant is incorrect. The reason is that there was a legacy log level in my configuration file:

config.log_level = Logger::INFO

Rails 2.2 uses its own logger, and doesn't understand the above line.

Solution: remove line, or use:

config.log_level = :info
Michiel de Mare
Good to know. I think I've come across this issue myself a few times.
Ryan Bigg
I ran into this when I switched my mailer and logger commands: config.log_level = :sendmailD'oh!
wesgarrison