puts vs logger in rails rake tasks

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

    You could create a new rake task to get this to work.

    desc "switch logger to stdout"
    task :to_stdout => [:environment] do
     Rails.logger = Logger.new(STDOUT)
    end
    

    This way when you execute your rake task you can add to_stdout first to get stdout log messages or don't include it to have messages sent to the default log file

    rake to_stdout some_task
    

提交回复
热议问题