Sha256: ae0a6b6c7bfc680f25242e000a340333ecb7941850eaef50ba46f6761f63c6d4

Contents?: true

Size: 777 Bytes

Versions: 48

Compression:

Stored size: 777 Bytes

Contents

module TrackerApi
  class Logger < Faraday::Response::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

48 entries across 48 versions & 2 rubygems

Version Path
tracker_api-0.2.6 lib/tracker_api/logger.rb
tracker_api-0.2.5 lib/tracker_api/logger.rb
tracker_api-0.2.4 lib/tracker_api/logger.rb
tracker_api-0.2.3 lib/tracker_api/logger.rb
tracker_api-0.2.2 lib/tracker_api/logger.rb
tracker_api-0.2.1 lib/tracker_api/logger.rb
tracker_api-0.2.0 lib/tracker_api/logger.rb
tracker_api-0.1.0 lib/tracker_api/logger.rb