Class: Attio::RequestLogger Private
- Inherits:
-
Object
- Object
- Attio::RequestLogger
- Defined in:
- lib/attio/logger.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Specialized logger for API request/response logging
This class provides sanitized logging of HTTP requests and responses, automatically redacting sensitive information like API keys.
Instance Attribute Summary collapse
- #log_level ⇒ Object readonly private
- #logger ⇒ Object readonly private
Instance Method Summary collapse
-
#initialize(logger:, log_level: :debug) ⇒ RequestLogger
constructor
private
A new instance of RequestLogger.
- #log_request(method, url, headers, body) ⇒ Object private
- #log_response(response, duration) ⇒ Object private
- #sanitize_body(body) ⇒ Object private private
- #sanitize_headers(headers) ⇒ Object private private
Constructor Details
#initialize(logger:, log_level: :debug) ⇒ RequestLogger
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of RequestLogger.
75 76 77 78 |
# File 'lib/attio/logger.rb', line 75 def initialize(logger:, log_level: :debug) @logger = logger @log_level = log_level end |
Instance Attribute Details
#log_level ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
73 74 75 |
# File 'lib/attio/logger.rb', line 73 def log_level @log_level end |
#logger ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
73 74 75 |
# File 'lib/attio/logger.rb', line 73 def logger @logger end |
Instance Method Details
#log_request(method, url, headers, body) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
80 81 82 83 84 85 86 87 88 |
# File 'lib/attio/logger.rb', line 80 def log_request(method, url, headers, body) return unless logger logger.send(log_level, "API Request", method: method.to_s.upcase, url: url, headers: sanitize_headers(headers), body: sanitize_body(body)) end |
#log_response(response, duration) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
90 91 92 93 94 95 96 97 98 |
# File 'lib/attio/logger.rb', line 90 def log_response(response, duration) return unless logger logger.send(log_level, "API Response", status: response.code, duration_ms: (duration * 1000).round(2), headers: response.headers, body_size: response.body&.bytesize) end |
#sanitize_body(body) ⇒ Object (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
110 111 112 113 114 115 116 117 118 |
# File 'lib/attio/logger.rb', line 110 private def sanitize_body(body) return nil unless body if body.is_a?(String) && body.length > 1000 "#{body[0..1000]}... (truncated)" else body end end |
#sanitize_headers(headers) ⇒ Object (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
100 101 102 103 104 105 106 107 108 |
# File 'lib/attio/logger.rb', line 100 private def sanitize_headers(headers) headers.transform_values do |value| if value.include?("Bearer") value.gsub(/Bearer\s+[\w\-]+/, "Bearer [REDACTED]") else value end end end |