Ruby on rails 在生产模式下登录RubyonRails
我想查看控制器中的一些变量,它尝试了以下操作:Ruby on rails 在生产模式下登录RubyonRails,ruby-on-rails,logging,production,Ruby On Rails,Logging,Production,我想查看控制器中的一些变量,它尝试了以下操作: Rails.logger.debug“年:{Time.now.Year}” 放置“年:{Time.now.Year},月:{@Month}” 我在哪里可以看到记录器或生产模式下的输出?我需要这样设置才能在某处查看这些日志吗?生产中的正常日志级别是info,因此debug日志不显示。 将日志记录更改为 Rails.logger.info "Year: #{Time.now.year}" 在production.log中显示它 或者(但不是一个好主意
Rails.logger.debug“年:{Time.now.Year}”
放置“年:{Time.now.Year},月:{@Month}”
我在哪里可以看到记录器或生产模式下的输出?我需要这样设置才能在某处查看这些日志吗?生产中的正常日志级别是
info
,因此debug
日志不显示。将日志记录更改为
Rails.logger.info "Year: #{Time.now.year}"
在production.log
中显示它
或者(但不是一个好主意),您可以在/config/environments/production.rb
中提高日志记录级别:
config.log_level = :debug
更新Rails 4.2:
现在,所有环境中的默认调试级别都是:debug
(如@nabilh所述)。如果您想减少生产环境中的闲聊,可以将
/config/environments/production.rb
中的日志级别重置为前者:info
:
config.log_level = :info
虽然我相信@martin-m是正确的,您可能不想在
/config/environments/production.rb
中使用config.log\u level=:debug
,但我相信从Rails 4.2开始,所有环境中的默认日志记录级别都是debug
。因此,除非您另有规定,否则debug
日志(以及所有级别的日志)将显示在生产中
因此,在回答您的问题时,您现在可以写:
Rails.logger.debug“年:{Time.now.Year}”
并在/log/production.log
中查看结果
有关更多详细文档,请参阅。是Rails 4.1的文档,用于比较