Sha256: dd49a835302595add69a7e7350eff6e946a218fe515572c1a0b57581a53fd131

Contents?: true

Size: 923 Bytes

Versions: 2

Compression:

Stored size: 923 Bytes

Contents

require 'puff/instrumentation/redis'

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

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

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

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

        name = "%s (%.2fms)" % ["Redis", event.duration]
        cmds = event.payload[:commands]

        output = "  #{color(name, RED, true)}"

        cmds.each do |name, *args|
          if args.present?
            output << "  #{name.to_s.upcase} #{args.join(" ")}"
          else
            output << "  #{name.to_s.upcase}"
          end
        end

        debug output
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
puff-0.4.0 lib/puff/instrumentation/log_subscriber.rb
puff-0.3.1 lib/puff/instrumentation/log_subscriber.rb