puts vs logger in rails rake tasks

后端 未结 8 1533
情书的邮戳
情书的邮戳 2021-01-30 06:24

In a rake task if I use puts command then I see the output on console. However I will not see that message in log file when app is deployed on production.

However if I s

8条回答
  •  南方客
    南方客 (楼主)
    2021-01-30 06:36

    Put this in application.rb, or in a rake task initialize code

    if defined?(Rails) && (Rails.env == 'development')
      Rails.logger = Logger.new(STDOUT)
    end
    

    This is Rails 3 code. Note that this will override logging to development.log. If you want both STDOUT and development.log you'll need a wrapper function.

    If you'd like this behaviour only in the Rails console, place the same block of code in your ~/.irbrc.

提交回复
热议问题