Sha256: e944f1b51ecbd54b1edcadd63b4ae382d0c75a37c3751dbf7f42afa8a49605d7

Contents?: true

Size: 992 Bytes

Versions: 1

Compression:

Stored size: 992 Bytes

Contents

module MongoidRailsInstrumentation
  class MopedLogSubscriber < ActiveSupport::LogSubscriber
    def self.runtime=(value)
      Thread.current["moped_rails_runtime"] = value
    end

    def self.runtime
      Thread.current["moped_rails_runtime"] ||= 0
    end

    def self.query_count=(value)
      Thread.current["moped_rails_query_count"] = value
    end

    def self.query_count
      Thread.current["moped_rails_query_count"] ||= 0
    end

    def self.reset_runtime!
      rt, self.runtime = runtime, 0
      self.query_count = 0
      rt
    end

    def moped(duration)
      self.class.runtime += duration
    end

    def start_processing(event)
      MopedLogSubscriber.reset_runtime!
    end

    def process_action(event)
      runtime = ("Mongo: (%.4fms) | Query count: #{MopedLogSubscriber.query_count}" % MopedLogSubscriber.runtime)
      info(runtime)
    end

    def logger
      ActionController::Base.logger
    end
  end 
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mongoid-rails-instrumentation-0.0.1 lib/mongoid-rails-instrumentation/log_subscriber.rb