Class: RailsApiLogger::Logger
- Inherits:
-
Object
- Object
- RailsApiLogger::Logger
- Defined in:
- app/models/rails_api_logger/logger.rb
Instance Method Summary collapse
- #call(url, request) ⇒ Object
-
#initialize(loggable = nil, skip_request_body: false, skip_response_body: false) ⇒ Logger
constructor
A new instance of Logger.
Constructor Details
#initialize(loggable = nil, skip_request_body: false, skip_response_body: false) ⇒ Logger
Returns a new instance of Logger.
3 4 5 6 7 |
# File 'app/models/rails_api_logger/logger.rb', line 3 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
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/models/rails_api_logger/logger.rb', line 9 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.} if log raise ensure log.ended_at = Time.current log.save! end |