本文介绍了Rails production.log 文件为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Rails 2.3.13,在我的 environments/production.rb 中,我有:

I'm using Rails 2.3.13 and in my environments/production.rb, I have:

config.log_level = :info
RAILS_DEFAULT_LOGGER = SyslogLogger.new('mysite-platform-production')

然而我的 log/production.log 是空的.为什么会这样?

Yet my log/production.log is empty. Why would that be?

推荐答案

您正在实例化一个 SyslogLogger,因此您的日志记录将进入 syslog(在大多数情况下作为 中的文件提供)/var/log/syslog 在 Unix 系统上)而不是日志文件.您传递给记录器 (mysite-platform-production) 的参数是 syslog 使用的标识符,而不是文件名.

You are instantiating a SyslogLogger, so your logging will go into the syslog (in most cases available as a file in /var/log/syslog on Unix systems) and not into a logfile. The parameter you pass to the logger (mysite-platform-production) is the identifier used by syslog and not a filename.

如果您想记录到日志目录中的文件,您必须按如下方式设置记录器:

If you want to log to a file in your log directory, you have to set up your logger as follows:

RAILS_DEFAULT_LOGGER = Logger.new('log/production.log')

但是:我很确定您实际上不必明确地这样做,但它是由 Rails 默认完成的,所以我建议不要设置 RAILS_DEFAULT_LOGGER 在你的代码中,你应该得到一个隐式登录到 log/production.log 的记录器......

But: I am pretty sure that you don't actually have to do that explicitly but that it is done by default by Rails, so I suggest just not setting RAILS_DEFAULT_LOGGER in your code and you should get a logger that logs into log/production.log implicitly...

这篇关于Rails production.log 文件为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 22:03