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.13.0 lib/tracker_api/logger.rb
tracker_api-1.12.0 lib/tracker_api/logger.rb
tracker_api-1.11.0 lib/tracker_api/logger.rb
tracker_api-1.10.0 lib/tracker_api/logger.rb
tracker_api-1.9.1 lib/tracker_api/logger.rb
tracker_api-1.9.0 lib/tracker_api/logger.rb
v2gpti-1.3.5 tracker_api/lib/tracker_api/logger.rb
v2gpti-1.3.4 tracker_api/lib/tracker_api/logger.rb
v2gpti-1.3.3 tracker_api/lib/tracker_api/logger.rb
v2gpti-1.3.2 tracker_api/lib/tracker_api/logger.rb
v2gpti-1.3.1 tracker_api/lib/tracker_api/logger.rb
tracker_api-1.8.0 lib/tracker_api/logger.rb
tracker_api-1.7.1 lib/tracker_api/logger.rb
tracker_api-1.7.0 lib/tracker_api/logger.rb
v2gpti-1.3.0 tracker_api/lib/tracker_api/logger.rb
v2gpti-1.2.9 tracker_api/lib/tracker_api/logger.rb
tracker_api-1.6.0 lib/tracker_api/logger.rb
tracker_api-1.5.0 lib/tracker_api/logger.rb
v2gpti-1.2.8 tracker_api/lib/tracker_api/logger.rb
tracker_api-1.4.1 lib/tracker_api/logger.rb