Module: ActiveSupport::OperationLogger::EventSubscriberFactory
- Defined in:
- lib/active_support/operation_logger.rb
Overview
A generic factory responsible for creating classes that can be used to create LogSubscribers that integrate with ActiveSupport::Notifications and mirror the functionality of ActiveRecord::LogSubscriber
Class Method Summary collapse
Class Method Details
.subscriber_for(klass) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/active_support/operation_logger.rb', line 52 def self.subscriber_for(klass) Class.new(ActiveSupport::LogSubscriber) do def initialize super @odd = false end def odd? @odd = !@odd end def call(event) name = "#{event.payload[:name]} (#{event.duration.round(1)}ms)" command = event.payload[:command] if odd? name = color(name, ActiveSupport::LogSubscriber::CYAN, true) command = color(command, nil, true) else name = color(name, ActiveSupport::LogSubscriber::MAGENTA, true) end debug " #{name} #{command}" end end end |