问题描述
我想在控制器中查看一些变量,它尝试了以下操作:
I would like to view some variables in controller, it tried the following:
Rails.logger.debug "Year: #{Time.now.year}"
puts "Year: #{Time.now.year}, Month: #{@month}"
我在哪里可以看到Logger或Puts进入生产模式的输出?我是否需要设置一些内容以便在某个地方查看这些内容?
where can I see the output for Logger or Puts in production mode? Do I need so set something up to view these somewhere?
推荐答案
生产中的常规日志级别为info
,因此不会显示debug
日志.
将您的日志记录更改为
The normal log level in production is info
, so debug
logs are not shown.
Change your logging to
Rails.logger.info "Year: #{Time.now.year}"
以在production.log
中显示.
或者(但不是一个好主意),您可以在/config/environments/production.rb
中提高日志记录级别:
Alternatively (but not a good idea) you can raise the logging level in /config/environments/production.rb
:
config.log_level = :debug
更新 Rails 4.2:
Update Rails 4.2:
现在,所有环境中的默认调试级别为:debug
(如@nabilh所述).
如果要使生产环境减少混乱,可以将/config/environments/production.rb
中的日志级别重置为以前的:info
:
Now the default debug level in all environments is :debug
(as @nabilh mentioned).
If you want you production environment less chattery, you can reset your log level in /config/environments/production.rb
to the former :info
:
config.log_level = :info
这篇关于以生产模式登录Ruby on Rails的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!