Sha256: c46a3fe2fe7b4ee911ab0787322fde4c0052acaa9157a5fc5c4dce9be220c073

Contents?: true

Size: 639 Bytes

Versions: 2

Compression:

Stored size: 639 Bytes

Contents

# frozen_string_literal: true

module IIPolicy
  class LogSubscriber < ActiveSupport::LogSubscriber
    def call(event)
      debug do
        policy = event.payload[:policy]
        action = event.payload[:action]
        item = " for #{policy.item.class}##{policy.item.id}" if policy.item
        "Called #{policy.class}##{action}#{item} and return #{policy._result} (#{additional_log(event)})"
      end
    end

    def additional_log(event)
      additions = ["Duration: %.1fms" % event.duration]
      additions << "Allocations: %d" % event.allocations if event.respond_to?(:allocations)
      additions.join(', ')
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ii_policy-2.0.0 lib/ii_policy/log_subscriber.rb
ii_policy-1.1.0 lib/ii_policy/log_subscriber.rb