Class: Worldline::Acquiring::SDK::Logging::RequestLogMessageBuilder
- Inherits:
-
LogMessageBuilder
- Object
- LogMessageBuilder
- Worldline::Acquiring::SDK::Logging::RequestLogMessageBuilder
- Defined in:
- lib/worldline/acquiring/sdk/logging/request_log_message_builder.rb
Overview
Class that converts data about a request into a properly formatted log message. Formats request id, http method, uri, headers and body 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, method, uri, body_obfuscator = Obfuscation::BodyObfuscator.default_obfuscator, header_obfuscator = Obfuscation::HeaderObfuscator.default_obfuscator) ⇒ RequestLogMessageBuilder
constructor
A new instance of RequestLogMessageBuilder.
Methods inherited from LogMessageBuilder
#add_headers, #is_binary, #set_body, #to_s
Constructor Details
#initialize(request_id, method, uri, body_obfuscator = Obfuscation::BodyObfuscator.default_obfuscator, header_obfuscator = Obfuscation::HeaderObfuscator.default_obfuscator) ⇒ RequestLogMessageBuilder
Returns a new instance of RequestLogMessageBuilder.
13 14 15 16 17 18 19 |
# File 'lib/worldline/acquiring/sdk/logging/request_log_message_builder.rb', line 13 def initialize(request_id, method, uri, body_obfuscator = Obfuscation::BodyObfuscator.default_obfuscator, header_obfuscator = Obfuscation::HeaderObfuscator.default_obfuscator) super(request_id, body_obfuscator, header_obfuscator) @method = method @uri = uri end |
Instance Method Details
#get_message ⇒ Object
Constructs and returns a log message based on the request data. The log message is a string.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/worldline/acquiring/sdk/logging/request_log_message_builder.rb', line 22 def msg_template_without_body = "Outgoing request (requestId='%s'):\n" + " method: '%s'\n" + " uri: '%s'\n" + " headers: '%s'" msg_template_with_body = msg_template_without_body + "\n" + " content-type: '%s'\n" + " body: '%s'" return sprintf(msg_template_without_body, @request_id, empty_if_null(@method), format_uri, @headers) if @body.nil? sprintf(msg_template_with_body, @request_id, empty_if_null(@method), format_uri, @headers, empty_if_null(@content_type), @body) end |