Sha256: a1ae04dda38c54999ff5e99dd93f55d43ce88bf7501f2a1fe566f32276494882

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

class StoredSession::LogSubscriber < ActiveSupport::LogSubscriber
  def initialize
    super
    @logger = logger || StoredSession.logger
  end

  attr_writer :logger

  def logger
    @logger ||= StoredSession.logger
  end

  def session_read(event)
    debug formatted_event(event, "Session Read", **event.payload.slice(:sid))
  end
  subscribe_log_level :session_read, :debug

  def session_write(event)
    debug formatted_event(event, "Session Write", **event.payload.slice(:sid))
  end
  subscribe_log_level :session_write, :debug

  def session_delete(event)
    debug formatted_event(event, "Session Delete", **event.payload.slice(:sid))
  end
  subscribe_log_level :session_delete, :debug

  private
    def formatted_event(event, operation, **)
      "  [StoredSession] #{operation} in #{formatted_duration(event)} (#{formatted_payload(**)})"
    end

    def formatted_duration(event)
      "%.1fms" % event.duration
    end

    def formatted_payload(**attributes)
      attributes.map { |k, v| "#{k}: #{v.inspect}" }.join(" | ")
    end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
stored_session-0.4.0 lib/stored_session/log_subscriber.rb
stored_session-0.3.0 lib/stored_session/log_subscriber.rb