Logging in Ruby on Rails in Production Mode

后端 未结 2 1204
陌清茗
陌清茗 2021-02-02 06:17

I would like to view some variables in controller, it tried the following:

Rails.logger.debug \"Year: #{Time.now.year}\"

puts \"Year: #{Time.n

2条回答
  •  不思量自难忘°
    2021-02-02 06:30

    While I believe @martin-m is right that you probably don't want to clutter your logs by using config.log_level = :debug in /config/environments/production.rb, I believe the default logging level in all environments is debug as of Rails 4.2. So debug logs (and all levels up) will be shown in production unless you specify otherwise.

    So in response to your question, you can now write:

    Rails.logger.debug "Year: #{Time.now.year}" and see the results in /log/production.log.

    See here for more detailed documentation. Here is the documentation for Rails 4.1 for comparison.

提交回复
热议问题