Sha256: df1b92e00551de7cc3d47b4541e23ca929dc944fcfad5c177b4f14e612095b6f

Contents?: true

Size: 979 Bytes

Versions: 23

Compression:

Stored size: 979 Bytes

Contents

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

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

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

    def initialize
      super
      @odd_or_even = false
    end

    def reql(event)
      self.class.runtime += event.duration
      return unless logger.debug?

      name = '%s (%.1fms)' % [event.payload[:name], event.duration]
      reql  = event.payload[:reql]

      if odd?
        name = color(name, CYAN, true)
        reql  = color(reql, nil, true)
      else
        name = color(name, MAGENTA, true)
      end

      debug "  #{name} #{reql}"
    end

    def odd?
      @odd_or_even = !@odd_or_even
    end

    def logger
      MontageRails::Base.logger
    end
  end
end

MontageRails::LogSubscriber.attach_to :montage_rails

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
montage_rails-1.0.0 lib/montage_rails/log_subscriber.rb
montage_rails-0.7.4 lib/montage_rails/log_subscriber.rb
montage_rails-0.7.3 lib/montage_rails/log_subscriber.rb
montage_rails-0.7.2 lib/montage_rails/log_subscriber.rb
montage_rails-0.7.1 lib/montage_rails/log_subscriber.rb
montage_rails-0.7 lib/montage_rails/log_subscriber.rb
montage_rails-0.6.4 lib/montage_rails/log_subscriber.rb
montage_rails-0.6.3 lib/montage_rails/log_subscriber.rb
montage_rails-0.6.2 lib/montage_rails/log_subscriber.rb
montage_rails-0.6.1 lib/montage_rails/log_subscriber.rb
montage_rails-0.6.0 lib/montage_rails/log_subscriber.rb
montage_rails-0.5.0 lib/montage_rails/log_subscriber.rb
montage_rails-0.4.11 lib/montage_rails/log_subscriber.rb
montage_rails-0.4.10 lib/montage_rails/log_subscriber.rb
montage_rails-0.4.9 lib/montage_rails/log_subscriber.rb
montage_rails-0.4.8 lib/montage_rails/log_subscriber.rb
montage_rails-0.4.7 lib/montage_rails/log_subscriber.rb
montage_rails-0.4.6 lib/montage_rails/log_subscriber.rb
montage_rails-0.4.5 lib/montage_rails/log_subscriber.rb
montage_rails-0.4.4 lib/montage_rails/log_subscriber.rb