require 'faraday' # @private module FaradayMiddleware # @private class LoudLogger < Faraday::Middleware extend Forwardable def_delegators :@logger, :debug, :info, :warn, :error, :fatal def initialize(app, options = {}) super @app = app @logger = options.fetch(:logger) do require 'logger' ::Logger.new($stdout) end end 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 private def filter(output) output end def request_info(env) format('Started %s request to: %s', method: env[:method].to_s.upcase, url: filter(env[:url])) end def response_info(env, response_time) format( 'Response from %s; Status: %d; Time: %