Sha256: d99339ec94a34b0e924939231ba1a8bfbf28cf50c644360dcccdd5e466679f5e

Contents?: true

Size: 948 Bytes

Versions: 17

Compression:

Stored size: 948 Bytes

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
    end
  end
end

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

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/faraday-2.5.2/lib/faraday/response/logger.rb
faraday-2.6.0 lib/faraday/response/logger.rb
tdiary-5.2.3 vendor/bundle/ruby/3.1.0/gems/faraday-2.5.2/lib/faraday/response/logger.rb
faraday-2.5.2 lib/faraday/response/logger.rb
faraday-2.5.1 lib/faraday/response/logger.rb
faraday-2.5.0 lib/faraday/response/logger.rb
faraday-2.4.0 lib/faraday/response/logger.rb
tdiary-5.2.2 vendor/bundle/ruby/3.1.0/gems/faraday-2.3.0/lib/faraday/response/logger.rb
faraday-2.3.0 lib/faraday/response/logger.rb
faraday-2.2.0 lib/faraday/response/logger.rb
faraday-2.1.0 lib/faraday/response/logger.rb
faraday-2.0.1 lib/faraday/response/logger.rb
faraday-2.0.0 lib/faraday/response/logger.rb
faraday-2.0.0.alpha.pre.4 lib/faraday/response/logger.rb
faraday-2.0.0.alpha.pre.3 lib/faraday/response/logger.rb
faraday-2.0.0.alpha.pre.2 lib/faraday/response/logger.rb
faraday-2.0.0.alpha.pre.1 lib/faraday/response/logger.rb