Class: ApiEntreprise::Commons::Middleware::Logging

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/api_entreprise/commons/middleware/logging.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, logger: nil, redact_query: false) ⇒ Logging

Returns a new instance of Logging.



10
11
12
13
14
# File 'lib/api_entreprise/commons/middleware/logging.rb', line 10

def initialize(app, logger: nil, redact_query: false)
  super(app)
  @logger = logger
  @redact_query = redact_query
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/api_entreprise/commons/middleware/logging.rb', line 16

def call(env)
  started = monotonic_now
  response = @app.call(env)
  log(env, response, monotonic_now - started) if @logger
  response
rescue StandardError => e
  log_error(env, e, monotonic_now - started) if @logger
  raise
end