Sha256: a31676c64934e940a0842f376545032e579c0a72e6be601454bf5530c54c4675

Contents?: true

Size: 719 Bytes

Versions: 1

Compression:

Stored size: 719 Bytes

Contents

# frozen_string_literal: true

require "logger"

class RequestLogger < Faraday::Middleware
  def initialize(app, logger = nil)
    super(app)
    @logger = logger || Logger.new($stdout)
  end

  def call(env)
    @logger.info "Request Method: #{env.method.upcase}"
    @logger.info "Request URL: #{env.url}"
    @logger.info "Request Headers: #{env.request_headers}"
    @logger.info "Request Body: #{env.body}"
    @logger.info "Request Params: #{env.params}"

    @app.call(env).on_complete do |response_env|
      @logger.info "Response Status: #{response_env.status}"
      @logger.info "Response Headers: #{response_env.response_headers}"
      @logger.info "Response Body: #{response_env.body}"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mi-service-1.0.0 lib/mi/logger.rb