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