Sha256: 8fe03ef791f34b068bfcfc89c54dae2286144fd2e0b36ece3e0e24e2f5533e68

Contents?: true

Size: 726 Bytes

Versions: 4

Compression:

Stored size: 726 Bytes

Contents

module RailsOps
  # This class subscribes to Rails Ops events via the ActiveSupport
  # instrumentation API.
  class LogSubscriber < ActiveSupport::LogSubscriber
    # This gets called whenever an operation has been performed and logs the
    # operation via Rails' `debug` logging method.
    def run(event)
      op = event.payload[:operation]

      return if op.class.logging_skipped?

      message = 'OP'

      profile = ::RailsOps::Profiler.node(op.object_id)
      message += " (#{profile.t_self_ms.round(1)}ms / #{profile.t_kids_ms.round(1)}ms)"
      profile.free

      message = color(message, YELLOW, true)
      message += color(" #{op.class.name}", YELLOW, false)

      debug "  #{message}"
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rails_ops-1.0.0.beta4 lib/rails_ops/log_subscriber.rb
rails_ops-1.0.0.beta3 lib/rails_ops/log_subscriber.rb
rails_ops-1.0.0.beta2 lib/rails_ops/log_subscriber.rb
rails_ops-1.0.0.beta1 lib/rails_ops/log_subscriber.rb