Class: MongoidRailsInstrumentation::MopedLogSubscriber
- Inherits:
-
ActiveSupport::LogSubscriber
- Object
- ActiveSupport::LogSubscriber
- MongoidRailsInstrumentation::MopedLogSubscriber
- Defined in:
- lib/mongoid-rails-instrumentation/log_subscriber.rb
Class Method Summary collapse
- .query_count ⇒ Object
- .query_count=(value) ⇒ Object
- .reset_runtime! ⇒ Object
- .runtime ⇒ Object
- .runtime=(value) ⇒ Object
Instance Method Summary collapse
- #logger ⇒ Object
- #moped(duration) ⇒ Object
- #process_action(event) ⇒ Object
- #start_processing(event) ⇒ Object
Class Method Details
.query_count ⇒ Object
15 16 17 |
# File 'lib/mongoid-rails-instrumentation/log_subscriber.rb', line 15 def self.query_count Thread.current["moped_rails_query_count"] ||= 0 end |
.query_count=(value) ⇒ Object
11 12 13 |
# File 'lib/mongoid-rails-instrumentation/log_subscriber.rb', line 11 def self.query_count=(value) Thread.current["moped_rails_query_count"] = value end |
.reset_runtime! ⇒ Object
19 20 21 22 23 |
# File 'lib/mongoid-rails-instrumentation/log_subscriber.rb', line 19 def self.reset_runtime! rt, self.runtime = runtime, 0 self.query_count = 0 rt end |
.runtime ⇒ Object
7 8 9 |
# File 'lib/mongoid-rails-instrumentation/log_subscriber.rb', line 7 def self.runtime Thread.current["moped_rails_runtime"] ||= 0 end |
.runtime=(value) ⇒ Object
3 4 5 |
# File 'lib/mongoid-rails-instrumentation/log_subscriber.rb', line 3 def self.runtime=(value) Thread.current["moped_rails_runtime"] = value end |
Instance Method Details
#logger ⇒ Object
38 39 40 |
# File 'lib/mongoid-rails-instrumentation/log_subscriber.rb', line 38 def logger ActionController::Base.logger end |
#moped(duration) ⇒ Object
25 26 27 |
# File 'lib/mongoid-rails-instrumentation/log_subscriber.rb', line 25 def moped(duration) self.class.runtime += duration end |
#process_action(event) ⇒ Object
33 34 35 36 |
# File 'lib/mongoid-rails-instrumentation/log_subscriber.rb', line 33 def process_action(event) runtime = ("Mongo: (%.4fms) | Query count: #{MopedLogSubscriber.query_count}" % MopedLogSubscriber.runtime) info(runtime) end |
#start_processing(event) ⇒ Object
29 30 31 |
# File 'lib/mongoid-rails-instrumentation/log_subscriber.rb', line 29 def start_processing(event) MopedLogSubscriber.reset_runtime! end |