Sha256: 2913d7ff313ebf3437b1d0993eb666b20b60af2d111ec11fdee96f066f47f051

Contents?: true

Size: 1.03 KB

Versions: 41

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

require 'forwardable'
require 'logger'
require 'faraday/logging/formatter'

module Faraday
  class Response
    # Logger is a middleware that logs internal events in the HTTP request
    # lifecycle to a given Logger object. By default, this logs to STDOUT. See
    # Faraday::Logging::Formatter to see specifically what is logged.
    class Logger < Middleware
      def initialize(app, logger = nil, options = {})
        super(app)
        logger ||= ::Logger.new($stdout)
        formatter_class = options.delete(:formatter) || Logging::Formatter
        @formatter = formatter_class.new(logger: logger, options: options)
        yield @formatter if block_given?
      end

      def call(env)
        @formatter.request(env)
        super
      end

      def on_complete(env)
        @formatter.response(env)
      end

      def on_error(exc)
        @formatter.exception(exc) if @formatter.respond_to?(:exception)
      end
    end
  end
end

Faraday::Response.register_middleware(logger: Faraday::Response::Logger)

Version data entries

41 entries across 41 versions & 5 rubygems

Version Path
es_cli-0.1.0 vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/response/logger.rb
faraday-2.12.2 lib/faraday/response/logger.rb
faraday-2.12.1 lib/faraday/response/logger.rb
moneykit-0.1.15 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/lib/faraday/response/logger.rb
moneykit-0.1.14 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/lib/faraday/response/logger.rb
faraday-2.12.0 lib/faraday/response/logger.rb
faraday-2.11.0 lib/faraday/response/logger.rb
moneykit-0.1.13 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/lib/faraday/response/logger.rb
moneykit-0.1.12 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/lib/faraday/response/logger.rb
moneykit-0.1.11 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/lib/faraday/response/logger.rb
faraday-2.10.1 lib/faraday/response/logger.rb
faraday-2.10.0 lib/faraday/response/logger.rb
faraday-2.9.2 lib/faraday/response/logger.rb
faraday-2.9.1 lib/faraday/response/logger.rb
moneykit-0.1.10 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/lib/faraday/response/logger.rb
moneykit-0.1.9 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/lib/faraday/response/logger.rb
moneykit-0.1.6 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/lib/faraday/response/logger.rb
moneykit-0.1.5 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/lib/faraday/response/logger.rb
moneykit-0.1.4 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/lib/faraday/response/logger.rb
moneykit-0.1.3 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/lib/faraday/response/logger.rb