Class: FaradayMiddleware::LoudLogger

Inherits:
Faraday::Middleware
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/faraday/loud_logger.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ LoudLogger

Returns a new instance of LoudLogger.



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

def initialize(app, options = {})
  @app = app
  @logger = options.fetch(:logger) {
    require 'logger'
    ::Logger.new($stdout)
  }
end

Instance Method Details

#call(env) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/faraday/loud_logger.rb', line 18

def call(env)
  start_time = Time.now
  info  { request_info(env) }
  debug { request_debug(env) }
  @app.call(env).on_complete do
    end_time = Time.now
    response_time = end_time - start_time
    info  { response_info(env, response_time) }
    debug { response_debug(env) }
  end
end