Class: Worldline::Connect::SDK::Logging::ResponseLogMessageBuilder
- Inherits:
-
LogMessageBuilder
- Object
- LogMessageBuilder
- Worldline::Connect::SDK::Logging::ResponseLogMessageBuilder
- Defined in:
- lib/worldline/connect/sdk/logging/response_log_message_builder.rb
Overview
Class that converts data about a response into a properly formatted log message. Formats request id, status code, headers, body and time between request and response into a helpful message.
Instance Attribute Summary
Attributes inherited from LogMessageBuilder
#body, #body_obfuscator, #content_type, #header_obfuscator, #headers, #request_id
Instance Method Summary collapse
-
#get_message ⇒ Object
Constructs and returns a log message based on the request data.
-
#initialize(request_id, status_code, duration = -1,, body_obfuscator = Obfuscation::BodyObfuscator.default_obfuscator, header_obfuscator = Obfuscation::HeaderObfuscator.default_obfuscator) ⇒ ResponseLogMessageBuilder
constructor
A new instance of ResponseLogMessageBuilder.
Methods inherited from LogMessageBuilder
#add_headers, #is_binary, #set_body, #to_s
Constructor Details
#initialize(request_id, status_code, duration = -1,, body_obfuscator = Obfuscation::BodyObfuscator.default_obfuscator, header_obfuscator = Obfuscation::HeaderObfuscator.default_obfuscator) ⇒ ResponseLogMessageBuilder
Returns a new instance of ResponseLogMessageBuilder.
16 17 18 19 20 21 22 |
# File 'lib/worldline/connect/sdk/logging/response_log_message_builder.rb', line 16 def initialize(request_id, status_code, duration = -1, body_obfuscator = Obfuscation::BodyObfuscator.default_obfuscator, header_obfuscator = Obfuscation::HeaderObfuscator.default_obfuscator) super(request_id, body_obfuscator, header_obfuscator) @status_code = status_code @duration = duration end |
Instance Method Details
#get_message ⇒ Object
Constructs and returns a log message based on the request data. The log message is a string.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/worldline/connect/sdk/logging/response_log_message_builder.rb', line 25 def msg_template = "Incoming response (requestId='%s'" + ((@duration < 0) ? "" : ", %.3f ms") + "):\n" + " status-code: '%s'\n" + " headers: '%s'\n" + " content-type: '%s'\n" + " body: '%s'" return sprintf(msg_template, @request_id, @status_code, @headers, empty_if_null(@content_type), empty_if_null(@body)) if @duration < 0 sprintf(msg_template, @request_id, @duration, @status_code, @headers, empty_if_null(@content_type), empty_if_null(@body)) end |