Methods
Public Class methods
[ show source ]
# File activerecord/lib/active_record/log_subscriber.rb, line 16
16: def initialize
17: super
18: @odd_or_even = false
19: end
[ show source ]
# File activerecord/lib/active_record/log_subscriber.rb, line 11
11: def self.reset_runtime
12: rt, self.runtime = runtime, 0
13: rt
14: end
[ show source ]
# File activerecord/lib/active_record/log_subscriber.rb, line 7
7: def self.runtime
8: Thread.current["active_record_sql_runtime"] ||= 0
9: end
[ show source ]
# File activerecord/lib/active_record/log_subscriber.rb, line 3
3: def self.runtime=(value)
4: Thread.current["active_record_sql_runtime"] = value
5: end
Public Instance methods
[ show source ]
# File activerecord/lib/active_record/log_subscriber.rb, line 42
42: def logger
43: ActiveRecord::Base.logger
44: end
[ show source ]
# File activerecord/lib/active_record/log_subscriber.rb, line 38
38: def odd?
39: @odd_or_even = !@odd_or_even
40: end
[ show source ]
# File activerecord/lib/active_record/log_subscriber.rb, line 21
21: def sql(event)
22: self.class.runtime += event.duration
23: return unless logger.debug?
24:
25: name = '%s (%.1fms)' % [event.payload[:name], event.duration]
26: sql = event.payload[:sql].squeeze(' ')
27:
28: if odd?
29: name = color(name, CYAN, true)
30: sql = color(sql, nil, true)
31: else
32: name = color(name, MAGENTA, true)
33: end
34:
35: debug " #{name} #{sql}"
36: end