Class: MongoidRailsInstrumentation::MopedLogSubscriber

Inherits:
ActiveSupport::LogSubscriber
  • Object
show all
Defined in:
lib/mongoid-rails-instrumentation/log_subscriber.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.query_countObject



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

.runtimeObject



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

#loggerObject



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