diff options
author | José Valim <jose.valim@gmail.com> | 2010-01-12 18:29:48 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-01-13 01:19:23 +0100 |
commit | dc2e291a939e1089300bdac972cb7b63548d9ec1 (patch) | |
tree | e3872cabb5d8c87abb0a2f381ac2d326d34e0031 /activerecord/lib/active_record/railties | |
parent | fe3ceabeed6bde67eb9c0e64b27e133a66e13d83 (diff) | |
download | rails-dc2e291a939e1089300bdac972cb7b63548d9ec1.tar.gz rails-dc2e291a939e1089300bdac972cb7b63548d9ec1.tar.bz2 rails-dc2e291a939e1089300bdac972cb7b63548d9ec1.zip |
Move AR logging responsibilities to ActiveRecord::Railties::Subscriber.
Diffstat (limited to 'activerecord/lib/active_record/railties')
-rw-r--r-- | activerecord/lib/active_record/railties/subscriber.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/railties/subscriber.rb b/activerecord/lib/active_record/railties/subscriber.rb new file mode 100644 index 0000000000..fd873dbff8 --- /dev/null +++ b/activerecord/lib/active_record/railties/subscriber.rb @@ -0,0 +1,27 @@ +module ActiveRecord + module Railties + class Subscriber < Rails::Subscriber + def sql(event) + name = '%s (%.1fms)' % [event.payload[:name], event.duration] + sql = event.payload[:sql].squeeze(' ') + + if odd? + name = color(name, :cyan, true) + sql = color(sql, nil, true) + else + name = color(name, :magenta, true) + end + + debug " #{name} #{sql}" + end + + def odd? + @odd_or_even = !@odd_or_even + end + + def logger + ActiveRecord::Base.logger + end + end + end +end
\ No newline at end of file |