Class: Faraday::SpecificLogging

Inherits:
Middleware
  • Object
show all
Defined in:
lib/faraday/specific_loging.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ SpecificLogging

Returns a new instance of SpecificLogging.



6
7
8
9
10
11
12
# File 'lib/faraday/specific_loging.rb', line 6

def initialize(app, options = {})
  super(app)
  @logger = options[:logger]
  @call_logging  = options[:call_logging] || 'info'
  @target_key = options[:target_key]
  @message = options[:message] || ''
end

Instance Method Details

#call(env) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/faraday/specific_loging.rb', line 14

def call(env)
  return @app.call(env) if lost_options? || not_post_or_put?(env) || env.body.nil?

  request_body = parse_body(env)

  @logger.send(@call_logging, message: @message, @target_key.to_sym => request_body[@target_key.to_s])

  @app.call(env)
end