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

Attributes included from DependencyLoader

#load_error

Instance Method Summary collapse

Methods inherited from Middleware

#close

Methods included from DependencyLoader

#dependency, #inherited, #loaded?, #new

Methods included from MiddlewareRegistry

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

Constructor Details

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

Returns a new instance of Logger.

Yields:

  • (@formatter)

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

def initialize(app, logger = nil, options = {})
  super(app)
  logger ||= begin
    require 'logger'
    ::Logger.new($stdout)
  end
  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


23
24
25
26
# File 'lib/faraday/response/logger.rb', line 23

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

#on_complete(env) ⇒ Object


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

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