Sha256: 9729c8a48b9d416b4c436ead3fed515b39302d3a202f27e2ada4eb6dc6ed7b12

Contents?: true

Size: 913 Bytes

Versions: 13

Compression:

Stored size: 913 Bytes

Contents

# frozen_string_literal: true

module ActiveResource
  class LogSubscriber < ActiveSupport::LogSubscriber
    def request(event)
      result = event.payload[:result]

      # When result is nil, the connection could not even be initiated
      # with the server, so we log an internal synthetic error response (523).
      code    = result.try(:code)    || 523  # matches CloudFlare's convention
      message = result.try(:message) || "ActiveResource connection error"
      body    = result.try(:body)    || ""

      log_level_method = code.to_i < 400 ? :info : :error

      send log_level_method, "#{event.payload[:method].to_s.upcase} #{event.payload[:request_uri]}"
      send log_level_method, "--> %d %s %d (%.1fms)" % [code, message, body.to_s.length, event.duration]
    end

    def logger
      ActiveResource::Base.logger
    end
  end
end

ActiveResource::LogSubscriber.attach_to :active_resource

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
activeresource-6.1.4 lib/active_resource/log_subscriber.rb
activeresource-6.1.3 lib/active_resource/log_subscriber.rb
activeresource-6.1.2 lib/active_resource/log_subscriber.rb
activeresource-6.1.1 lib/active_resource/log_subscriber.rb
activeresource-6.1.0 lib/active_resource/log_subscriber.rb
ric-0.14.2 vendor/bundle/ruby/2.7.0/gems/activeresource-5.1.1/lib/active_resource/log_subscriber.rb
ric-0.14.1 vendor/bundle/ruby/2.7.0/gems/activeresource-5.1.1/lib/active_resource/log_subscriber.rb
activeresource-6.0.0 lib/active_resource/log_subscriber.rb
ric-0.14.0 vendor/bundle/ruby/2.7.0/gems/activeresource-5.1.1/lib/active_resource/log_subscriber.rb
activeresource-5.1.1 lib/active_resource/log_subscriber.rb
ric-0.13.0 vendor/bundle/ruby/2.5.0/gems/activeresource-5.1.0/lib/active_resource/log_subscriber.rb
ric-0.12.2 vendor/bundle/ruby/2.5.0/gems/activeresource-5.1.0/lib/active_resource/log_subscriber.rb
activeresource-5.1.0 lib/active_resource/log_subscriber.rb