Rails ActiveRecord :: Base.logger仅显示执行时间

时间:2014-12-23 05:40:29

标签: ruby-on-rails

有没有办法让Rails只显示SQL执行时间而不是自己显示SQL查询?

1 个答案:

答案 0 :(得分:0)

我提出了这个解决方案

1     class TimeLogFormatter < Logger 
2         def format_message(severity, timestamp, progname, msg)
3             time_capture = msg.match /\[\d+m\w.*\([\d\.]+ms\)/
4             if time_capture
5                 "\e#{time_capture}\e[0m\n"
6             end
7         end
8     end
9     ActiveRecord::Base.logger = TimeLogFormatter.new(STDOUT)