Class: MongoModel::LogSubscriber
- Inherits:
-
ActiveSupport::LogSubscriber
- Object
- ActiveSupport::LogSubscriber
- MongoModel::LogSubscriber
- Defined in:
- lib/mongomodel/log_subscriber.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ LogSubscriber
constructor
A new instance of LogSubscriber.
- #logger ⇒ Object
- #odd? ⇒ Boolean
- #query(event) ⇒ Object
Constructor Details
#initialize ⇒ LogSubscriber
Returns a new instance of LogSubscriber.
16 17 18 19 |
# File 'lib/mongomodel/log_subscriber.rb', line 16 def initialize super @odd_or_even = false end |
Class Method Details
.reset_runtime ⇒ Object
11 12 13 14 |
# File 'lib/mongomodel/log_subscriber.rb', line 11 def self.reset_runtime rt, self.runtime = runtime, 0 rt end |
.runtime ⇒ Object
7 8 9 |
# File 'lib/mongomodel/log_subscriber.rb', line 7 def self.runtime Thread.current["mongomodel_runtime"] ||= 0 end |
.runtime=(value) ⇒ Object
3 4 5 |
# File 'lib/mongomodel/log_subscriber.rb', line 3 def self.runtime=(value) Thread.current["mongomodel_runtime"] = value end |
Instance Method Details
#logger ⇒ Object
42 43 44 |
# File 'lib/mongomodel/log_subscriber.rb', line 42 def logger MongoModel.logger end |
#odd? ⇒ Boolean
38 39 40 |
# File 'lib/mongomodel/log_subscriber.rb', line 38 def odd? @odd_or_even = !@odd_or_even end |
#query(event) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/mongomodel/log_subscriber.rb', line 21 def query(event) self.class.runtime += event.duration return unless logger.debug? collection = '%s (%.1fms)' % [event.payload[:collection], event.duration] query = event.payload[:query] if odd? collection = color(collection, CYAN, true) query = color(query, nil, true) else collection = color(collection, MAGENTA, true) end debug " #{collection} #{query}" end |