ActiveSupport::LogSubscriber

class ActiveSupport::LogSubscriber

Parent:
Subscriber

ActiveSupport::LogSubscriber is an object set to consume ActiveSupport::Notifications with the sole purpose of logging them. The log subscriber dispatches notifications to a registered object based on its given namespace.

An example would be Active Record log subscriber responsible for logging queries:

module ActiveRecord
  class LogSubscriber < ActiveSupport::LogSubscriber
    def sql(event)
      "#{event.payload[:name]} (#{event.duration}) #{event.payload[:sql]}"
    end
  end
end

And it's finally registered as:

ActiveRecord::LogSubscriber.a