Class: CoreLibrary::SdkLogger
- Inherits:
-
ApiLogger
- Object
- ApiLogger
- CoreLibrary::SdkLogger
- Defined in:
- lib/apimatic-core/logger/sdk_logger.rb
Overview
This class is responsible for logging request and response info.
Instance Method Summary collapse
-
#initialize(logging_config) ⇒ SdkLogger
constructor
A new instance of SdkLogger.
- #log_request(request) ⇒ Object
- #log_response(response) ⇒ Object
Constructor Details
#initialize(logging_config) ⇒ SdkLogger
Returns a new instance of SdkLogger.
4 5 6 7 8 9 10 |
# File 'lib/apimatic-core/logger/sdk_logger.rb', line 4 def initialize(logging_config) @log_level = logging_config.log_level @logger = logging_config.logger @request_logging_config = logging_config.request_logging_config @response_logging_config = logging_config.response_logging_config @mask_sensitive_headers = logging_config.mask_sensitive_headers end |
Instance Method Details
#log_request(request) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/apimatic-core/logger/sdk_logger.rb', line 12 def log_request(request) content_type_header = LoggerHelper.get_content_type(request.headers) url = @request_logging_config.include_query_in_path ? request.query_url : request.query_url.split('?').first @logger.log(@log_level, "Request {#{METHOD}} {#{URL}} {#{CONTENT_TYPE_HEADER}}", { METHOD => request.http_method, URL => url, CONTENT_TYPE_HEADER => content_type_header }) (request) end |
#log_response(response) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/apimatic-core/logger/sdk_logger.rb', line 26 def log_response(response) content_type_header = LoggerHelper.get_content_type(response.headers) content_length_header = LoggerHelper.get_content_length(response.headers) @logger.log(@log_level, "Response {#{STATUS_CODE}} {#{CONTENT_LENGTH_HEADER}} {#{CONTENT_TYPE_HEADER}}", { STATUS_CODE => response.status_code, CONTENT_LENGTH_HEADER => content_length_header, CONTENT_TYPE_HEADER => content_type_header }) (response) end |