Class: Faraday::Response::Logger

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

Overview

Logger is a middleware that logs internal events in the HTTP request lifecycle to a given Logger object. By default, this logs to STDOUT. See Faraday::Logging::Formatter to see specifically what is logged.

Instance Attribute Summary

Attributes inherited from Middleware

#app, #options

Instance Method Summary collapse

Methods inherited from Middleware

#close

Methods included from MiddlewareRegistry

#lookup_middleware, #register_middleware, #registered_middleware, #unregister_middleware

Constructor Details

#initialize(app, logger = nil, options = {}) {|@formatter| ... } ⇒ Logger

Returns a new instance of Logger.

Yields:

  • (@formatter)


13
14
15
16
17
18
19
# File 'lib/faraday/response/logger.rb', line 13

def initialize(app, logger = nil, options = {})
  super(app)
  logger ||= ::Logger.new($stdout)
  formatter_class = options.delete(:formatter) || Logging::Formatter
  @formatter = formatter_class.new(logger: logger, options: options)
  yield @formatter if block_given?
end

Instance Method Details

#call(env) ⇒ Object



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

def call(env)
  @formatter.request(env)
  super
end

#on_complete(env) ⇒ Object



26
27
28
# File 'lib/faraday/response/logger.rb', line 26

def on_complete(env)
  @formatter.response(env)
end

#on_error(exc) ⇒ Object



30
31
32
# File 'lib/faraday/response/logger.rb', line 30

def on_error(exc)
  @formatter.exception(exc) if @formatter.respond_to?(:exception)
end