Rails: Unable to access log file
Asked Answered
P

2

15

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?

Prim answered 10/3, 2009 at 22:49 Comment(0)
P
27

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
Prim answered 11/3, 2009 at 0:56 Comment(5)
Good to know. I think I've come across this issue myself a few times.Fob
I ran into this when I switched my mailer and logger commands: config.log_level = :sendmail D'oh!Asiatic
Thanks for this, kept thinking it was a VirtualBox bug.Schenck
I was getting a similar error without the second error. Turned out cap deploy was creating share\log as root, and rails couldn't make the log file.Califate
Thank you very much, that was the most misleading error message ever. Thanks for figuring out.Antisemite
S
0

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?

Shirley answered 10/3, 2009 at 23:5 Comment(3)
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).Prim
@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?Shirley
Interesting - I should look into that. The error message was completely misleading though - nothing to do with the log file.Prim

© 2022 - 2024 — McMap. All rights reserved.