Class: MastercardCoreSdk::Core::RequestResponseLogger
- Inherits:
-
Object
- Object
- MastercardCoreSdk::Core::RequestResponseLogger
- Includes:
- Exceptions
- Defined in:
- lib/mastercard_core_sdk/core/request_response_logger.rb
Overview
Logs the request and response content.
Constant Summary collapse
- NEWLINE =
"\n"- @@logger =
Logging.logger[self]
Class Method Summary collapse
-
.log_request(request) ⇒ Object
Log the request content.
-
.log_response(response) ⇒ Object
Log the response content.
Class Method Details
.log_request(request) ⇒ Object
Log the request content.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/mastercard_core_sdk/core/request_response_logger.rb', line 16 def self.log_request(request) if request log_str = LOG_REQUEST_INFORMATION request_api_info = NEWLINE + LOG_REQUEST + request.[:method].to_s.upcase + HYPHEN + request.base_url + NEWLINE log_str += request_api_info headers = request.[:headers] body = request.[:body] if headers && headers.size > 0 headers.each do |param,value| log_str += NEWLINE + param.to_s + COLON + value.to_s end end if body log_str += NEWLINE + body.to_s end log_str += NEWLINE @@logger.info request_api_info @@logger.debug log_str else @@logger.error ERR_MSG_NULL_REQUEST raise SDKValidationError.new(ERR_MSG_NULL_REQUEST) end end |
.log_response(response) ⇒ Object
Log the response content.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/mastercard_core_sdk/core/request_response_logger.rb', line 47 def self.log_response(response) if response log_str = NEWLINE + LOG_RESPONSE_INFORMATION response_api_info = NEWLINE + LOG_RESPONSE + response. + HYPHEN + response.return_code.to_s.upcase + HYPHEN + response.code.to_s.upcase response_uri_info = NEWLINE + LOG_URI + HYPHEN + response.[:effective_url] log_str += response_api_info + response_uri_info headers = response.headers if headers && headers.size > 0 headers.each do |param, value| if value.is_a?(Array) value.each do |v| log_str += NEWLINE + param + COLON + v end else log_str += NEWLINE + param + COLON + value end end end if response.response_body response_body = response.response_body xml_mime = !!(response.headers['Content-Type'] =~ /xml/i) if xml_mime && response_body.include?("AccountNumber") response_body = mask_data(response_body) end log_str += NEWLINE + response_body.to_s end log_str += NEWLINE @@logger.info response_api_info @@logger.debug log_str else @@logger.error ERR_MSG_NULL_RESPONSE raise SDKValidationError.new(ERR_MSG_NULL_RESPONSE) end end |