Class: Faraday::Response::Logger
- Inherits:
-
Middleware
- Object
- Middleware
- Middleware
- Faraday::Response::Logger
- Extended by:
- Forwardable
- Defined in:
- lib/faraday/response/logger.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :headers => true, :bodies => false }
Instance Method Summary collapse
- #call(env) ⇒ Object
- #filter(filter_word, filter_replacement) ⇒ Object
-
#initialize(app, logger = nil, options = {}) {|_self| ... } ⇒ Logger
constructor
A new instance of Logger.
- #on_complete(env) ⇒ Object
Methods inherited from Middleware
dependency, inherited, loaded?, new
Methods included from MiddlewareRegistry
#fetch_middleware, #load_middleware, #lookup_middleware, #middleware_mutex, #register_middleware
Constructor Details
#initialize(app, logger = nil, options = {}) {|_self| ... } ⇒ Logger
Returns a new instance of Logger.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/faraday/response/logger.rb', line 9 def initialize(app, logger = nil, = {}) super(app) @logger = logger || begin require 'logger' ::Logger.new(STDOUT) end @filter = [] @options = DEFAULT_OPTIONS.merge() yield self if block_given? end |
Instance Method Details
#call(env) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/faraday/response/logger.rb', line 22 def call(env) info "#{env.method} #{apply_filters(env.url.to_s)}" debug('request') { apply_filters( dump_headers env.request_headers ) } if log_headers?(:request) debug('request') { apply_filters( dump_body(env[:body]) ) } if env[:body] && log_body?(:request) super end |
#filter(filter_word, filter_replacement) ⇒ Object
35 36 37 |
# File 'lib/faraday/response/logger.rb', line 35 def filter(filter_word, filter_replacement) @filter.push([ filter_word, filter_replacement ]) end |
#on_complete(env) ⇒ Object
29 30 31 32 33 |
# File 'lib/faraday/response/logger.rb', line 29 def on_complete(env) info('Status') { env.status.to_s } debug('response') { apply_filters( dump_headers env.response_headers ) } if log_headers?(:response) debug('response') { apply_filters( dump_body env[:body] ) } if env[:body] && log_body?(:response) end |