Sha256: e0e62a6d77202d7b5d29ea54f6f35ed5847b658e9d1b7de2853f31644c9d26fd

Contents?: true

Size: 1.13 KB

Versions: 19

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true
module FinAppsCore
  module Middleware
    class CustomLogger < Faraday::Response::Middleware
      extend Forwardable
      include FinAppsCore::Utils::ParameterFilter

      DEFAULT_OPTIONS = {bodies: false}.freeze

      def initialize(app, logger=nil, options={})
        super(app)
        @logger = logger || begin
          require 'logger'
          ::Logger.new(STDOUT)
        end
        @options = DEFAULT_OPTIONS.merge(options)
      end

      def_delegators :@logger, :debug, :info, :warn, :error, :fatal

      def call(env)
        debug "#{self.class.name}##{__method__} => URL: #{env.method.upcase} #{env.url}"
        debug "#{self.class.name}##{__method__} => Request Headers: #{dump env.request_headers}"
        super
      end

      def on_complete(env)
        debug "#{self.class.name}##{__method__} => Response Headers: #{dump env.response_headers}"
        debug "#{self.class.name}##{__method__} => Response Body: #{dump env.body}" if env.body
      end

      private

      def dump(value)
        skip_sensitive_data(value.is_a?(Array) ? value.to_h : value).to_json
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
finapps_core-2.0.20 lib/finapps_core/middleware/response/custom_logger.rb
finapps_core-2.0.19 lib/finapps_core/middleware/response/custom_logger.rb
finapps_core-2.0.18 lib/finapps_core/middleware/response/custom_logger.rb
finapps_core-2.0.17 lib/finapps_core/middleware/response/custom_logger.rb
finapps_core-2.0.16 lib/finapps_core/middleware/response/custom_logger.rb
finapps_core-2.0.15 lib/finapps_core/middleware/response/custom_logger.rb
finapps_core-2.0.14 lib/finapps_core/middleware/response/custom_logger.rb
finapps_core-2.0.13 lib/finapps_core/middleware/response/custom_logger.rb
finapps_core-2.0.12 lib/finapps_core/middleware/response/custom_logger.rb
finapps_core-2.0.11 lib/finapps_core/middleware/response/custom_logger.rb
finapps_core-2.0.10 lib/finapps_core/middleware/response/custom_logger.rb
finapps_core-2.0.9 lib/finapps_core/middleware/response/custom_logger.rb
finapps_core-2.0.8 lib/finapps_core/middleware/response/custom_logger.rb
finapps_core-2.0.7 lib/finapps_core/middleware/response/custom_logger.rb
finapps_core-2.0.6 lib/finapps_core/middleware/response/custom_logger.rb
finapps_core-2.0.5 lib/finapps_core/middleware/response/custom_logger.rb
finapps_core-2.0.4 lib/finapps_core/middleware/response/custom_logger.rb
finapps_core-2.0.3 lib/finapps_core/middleware/response/custom_logger.rb
finapps_core-2.0.2 lib/finapps_core/middleware/response/custom_logger.rb