Sha256: 709ea63476c726248a338f07caed13646f054756d094b77fe86eda8cfa4a97cf

Contents?: true

Size: 777 Bytes

Versions: 3

Compression:

Stored size: 777 Bytes

Contents

class Ey::Core::Logger < Faraday::Response::Middleware
  extend Forwardable

  def initialize(app, logger = nil)
    super(app)
    @logger = logger || ::Logger.new(nil)
  end

  def_delegators :@logger, :debug, :info, :warn, :error, :fatal

  def call(env)
    debug "REQUEST: #{env[:method].upcase} #{env[:url].to_s}"
    debug('request') { dump_headers env[:request_headers] }
    debug('request.body') { env[:body] }
    debug('')
    super
  end

  def on_complete(env)
    debug "RESPONSE: #{env[:status]}"
    debug('response') { dump_headers env[:response_headers] }
    debug('response.body') { env[:body] }
    debug('')
  end

  private

  def dump_headers(headers)
    headers.map { |k, v| "#{k}: #{v.inspect}" }.join("\n")
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ey-core-3.6.6 lib/ey-core/logger.rb
ey-core-3.4.5 lib/ey-core/logger.rb
ey-core-3.6.5 lib/ey-core/logger.rb