如何更改Rails 3.0的默认日志路径? [英] How to change Rails 3.0's default log path?
问题描述
由于公司内部软件的部署过程,我必须更改Rail应用程序的默认日志路径:基本上我的Rails应用程序以只读位置结尾,并且我需要将日志文件写在为此目的"目录中
I have to change my rail application's default log path because of my company's internal software deployment process: basically my rails app ends up on a read-only location, and I need the log files written in a directory "made for this".
在Rails 2.x中,我们曾经在FCGI脚本中添加了一些黑魔法,以在部署到产品上时强制使用.主持人:
With Rails 2.x we used to add some black magic in our FCGI script to force that in when deployed on prod. hosts:
class Rails::Configuration
def default_log_path
File.join(ENV['SOME_ENVIRONMENT_VAR'], "var/output/logs/rails.log")
end
end
但是,在Rails 2.3中,配置不再是一个类(它是一个模块),在我看来,那里也不再涉及任何default_log_path ...
However, Configuration isn't a class anymore in Rails 2.3 (it's a module), and it appears to me there isn't any default_log_path involved there anymore as well...
推荐答案
您只需要定义记录器
config.logger = ActiveSupport::BufferedLogger.new(File.join(ENV['SOME_ENVIRONMENT_VAR'], "var/output/logs/rails.log"))
此技巧也适用于Rails 2.然后,您可以根据环境定义您真正想要日志文件的位置.
This trick works with Rails 2 too. And you can define by environment where you really want your log file.
这篇关于如何更改Rails 3.0的默认日志路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!