Class: RailsApiLogger
- Inherits:
-
Object
- Object
- RailsApiLogger
- Defined in:
- lib/rails_api_logger.rb,
lib/generators/rails_api_logger/install_generator.rb
Defined Under Namespace
Modules: Generators Classes: Error
Instance Method Summary collapse
- #call(url, request) ⇒ Object
-
#initialize(loggable = nil, skip_request_body: false, skip_response_body: false) ⇒ RailsApiLogger
constructor
A new instance of RailsApiLogger.
Constructor Details
#initialize(loggable = nil, skip_request_body: false, skip_response_body: false) ⇒ RailsApiLogger
Returns a new instance of RailsApiLogger.
13 14 15 16 17 |
# File 'lib/rails_api_logger.rb', line 13 def initialize(loggable = nil, skip_request_body: false, skip_response_body: false) @loggable = loggable @skip_request_body = skip_request_body @skip_response_body = skip_response_body end |
Instance Method Details
#call(url, request) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rails_api_logger.rb', line 19 def call(url, request) log = OutboundRequestLog.from_request(request, loggable: @loggable, skip_request_body: @skip_request_body) yield.tap do |response| log.from_response(response, skip_response_body: @skip_response_body) end rescue => e log.response_body = {error: e.} raise ensure log.ended_at = Time.current log.save! end |