Class: Faraday::Response::Logger

Inherits:
Middleware show all
Extended by:
Forwardable
Defined in:
lib/faraday/response/logger.rb

Constant Summary

DEFAULT_OPTIONS =
{ :bodies => false }

Instance Method Summary collapse

Methods inherited from Middleware

dependency, inherited, loaded?, new

Methods included from MiddlewareRegistry

#fetch_middleware, #load_middleware, #lookup_middleware, #middleware_mutex, #register_middleware

Constructor Details

#initialize(app, logger = nil, options = {}) ⇒ Logger

Returns a new instance of Logger



9
10
11
12
13
14
15
16
# File 'lib/faraday/response/logger.rb', line 9

def initialize(app, logger = nil, options = {})
  super(app)
  @logger = logger || begin
    require 'logger'
    ::Logger.new(STDOUT)
  end
  @options = DEFAULT_OPTIONS.merge(options)
end

Instance Method Details

#call(env) ⇒ Object



20
21
22
23
24
25
# File 'lib/faraday/response/logger.rb', line 20

def call(env)
  info "#{env.method} #{env.url.to_s}"
  debug('request') { dump_headers env.request_headers }
  debug('request') { dump_body(env[:body]) } if env[:body] && log_body?(:request)
  super
end

#on_complete(env) ⇒ Object



27
28
29
30
31
# File 'lib/faraday/response/logger.rb', line 27

def on_complete(env)
  info('Status') { env.status.to_s }
  debug('response') { dump_headers env.response_headers }
  debug('response') { dump_body env[:body] } if env[:body] && log_body?(:response)
end