以生产模式登录Ruby on Rails [英] Logging in Ruby on Rails in Production Mode

查看:70
本文介绍了以生产模式登录Ruby on Rails的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在控制器中查看一些变量,它尝试了以下操作:

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆