puts vs logger in rails rake tasks

后端 未结 8 1537
情书的邮戳
情书的邮戳 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:29

    How about creating an application helper which detects which environment is running and does the right thing?

    def output_debug(info)
       if RAILS_ENV == "development"
          puts info
       else
          logger.info info
       end
    end
    

    Then call output_debug instead of puts or logger.info

提交回复
热议问题