Rails: Unable to access log file

£可爱£侵袭症+ 提交于 2020-01-19 07:29:18

问题


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?


回答1:


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



回答2:


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?



来源:https://stackoverflow.com/questions/632592/rails-unable-to-access-log-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!