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-1.4.0 lib/tracker_api/logger.rb
tracker_api-1.3.0 lib/tracker_api/logger.rb
tracker_api-1.2.1 lib/tracker_api/logger.rb
tracker_api-1.1.1 lib/tracker_api/logger.rb
tracker_api-1.1.0 lib/tracker_api/logger.rb
tracker_api-1.0.0 lib/tracker_api/logger.rb
tracker_api-0.2.12 lib/tracker_api/logger.rb
tracker_api-0.2.11 lib/tracker_api/logger.rb
v2gpti-1.2.7 tracker_api/lib/tracker_api/logger.rb
v2gpti-1.2.6 tracker_api/lib/tracker_api/logger.rb
v2gpti-1.2.5 tracker_api/lib/tracker_api/logger.rb
v2gpti-1.2.4 tracker_api/lib/tracker_api/logger.rb
tracker_api-0.2.10 lib/tracker_api/logger.rb
v2gpti-1.2.3 tracker_api/lib/tracker_api/logger.rb
v2gpti-1.2.2 tracker_api/lib/tracker_api/logger.rb
tracker_api-0.2.9 lib/tracker_api/logger.rb
v2gpti-1.2.1 tracker_api/lib/tracker_api/logger.rb
v2gpti-1.2.0 tracker_api/lib/tracker_api/logger.rb
tracker_api-0.2.8 lib/tracker_api/logger.rb
tracker_api-0.2.7 lib/tracker_api/logger.rb