Sha256: 05be89d31e25a2f78a0fb29f1913dbd919ee312d077088e501fb45e7f78e7a3c

Contents?: true

Size: 767 Bytes

Versions: 3

Compression:

Stored size: 767 Bytes

Contents

module TrackerApi
  class Logger < Faraday::Middleware
    extend Forwardable

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

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

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

    def on_complete(env)
      info("#{env[:status]} <= #{env[:url].to_s}")
      debug('response') { dump_headers env[:response_headers] }
      debug('response.body') { env[:body] }
    end

    private

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tracker_api-1.16.0 lib/tracker_api/logger.rb
tracker_api-1.15.0 lib/tracker_api/logger.rb
tracker_api-1.14.0 lib/tracker_api/logger.rb