Class: ActiveResource::LogSubscriber

Inherits:
ActiveSupport::LogSubscriber
  • Object
show all
Defined in:
lib/active_resource/log_subscriber.rb

Instance Method Summary collapse

Instance Method Details

#loggerObject



20
21
22
# File 'lib/active_resource/log_subscriber.rb', line 20

def logger
  ActiveResource::Base.logger
end

#request(event) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/active_resource/log_subscriber.rb', line 5

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