aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/log_subscriber.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-06-24 13:23:43 +0200
committerJosé Valim <jose.valim@gmail.com>2010-06-24 13:23:43 +0200
commit6788db824ab732b13493a9d702dd8fb89fa153c8 (patch)
treead9314fdd10b55ebb035959a71be0de921cb0d02 /activerecord/lib/active_record/log_subscriber.rb
parent5441e082f9478ddb3c676c681b09786f1391483c (diff)
downloadrails-6788db824ab732b13493a9d702dd8fb89fa153c8.tar.gz
rails-6788db824ab732b13493a9d702dd8fb89fa153c8.tar.bz2
rails-6788db824ab732b13493a9d702dd8fb89fa153c8.zip
Move Rails::LogSubscriber to ActiveSupport::LogSubscriber, allowing frameworks like ActiveRecord and ActiveResource to log outsude Rails::Application [#4816 state:resolved]
Diffstat (limited to 'activerecord/lib/active_record/log_subscriber.rb')
-rw-r--r--activerecord/lib/active_record/log_subscriber.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/log_subscriber.rb b/activerecord/lib/active_record/log_subscriber.rb
new file mode 100644
index 0000000000..71065f9908
--- /dev/null
+++ b/activerecord/lib/active_record/log_subscriber.rb
@@ -0,0 +1,32 @@
+module ActiveRecord
+ class LogSubscriber < ActiveSupport::LogSubscriber
+ def initialize
+ super
+ @odd_or_even = false
+ end
+
+ 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
+
+ActiveRecord::LogSubscriber.attach_to :active_record \ No newline at end of file