Logging in Ruby on Rails in Production Mode

后端 未结 2 1202
陌清茗
陌清茗 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:39

    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}"
    

    to show it in production.log.

    Alternatively (but not a good idea) you can raise the logging level in /config/environments/production.rb:

    config.log_level = :debug
    

    Update Rails 4.2:

    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
    

提交回复
热议问题