Adding filename to Rails logger info messages

后端 未结 2 636
长情又很酷
长情又很酷 2021-01-24 21:33

How to add the file name and line number in Rails\' log message? My current format is something like

[INFO : 12-09-27 10:12:30]

I want to chang

2条回答
  •  猫巷女王i
    2021-01-24 22:02

    In case any one is looking for a similar solution for Rails 4. It would be:

    class ActiveSupport::Logger::SimpleFormatter
      def call(severity, time, progname, msg)
        "[#{severity} #{time} #{caller(0).first.match(/.*:\d+/)[0]}] #{msg}\n"
      end
    end
    

提交回复
热议问题