Module: Sumologic::Http::DebugLogger
- Defined in:
- lib/sumologic/http/debug_logger.rb
Overview
Handles debug logging for HTTP requests and responses Only logs when $DEBUG is enabled
Class Method Summary collapse
- .log_request(method, uri, body, headers = {}) ⇒ Object
- .log_request_body(body) ⇒ Object
- .log_response(response) ⇒ Object
- .log_response_body(body) ⇒ Object
Class Method Details
.log_request(method, uri, body, headers = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/sumologic/http/debug_logger.rb', line 12 def log_request(method, uri, body, headers = {}) return unless $DEBUG warn "\n[DEBUG] API Request:" warn " Method: #{method.to_s.upcase}" warn " URL: #{uri}" warn " Cookie: #{headers['Cookie']}" if headers['Cookie'] log_request_body(body) if body warn '' end |
.log_request_body(body) ⇒ Object
32 33 34 35 36 |
# File 'lib/sumologic/http/debug_logger.rb', line 32 def log_request_body(body) warn " Body: #{JSON.pretty_generate(body)}" rescue JSON::GeneratorError warn " Body: #{body.inspect}" end |
.log_response(response) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/sumologic/http/debug_logger.rb', line 23 def log_response(response) return unless $DEBUG warn '[DEBUG] API Response:' warn " Status: #{response.code} #{response.message}" log_response_body(response.body) warn '' end |
.log_response_body(body) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/sumologic/http/debug_logger.rb', line 38 def log_response_body(body) truncated = body.length > 500 display_body = truncated ? "#{body[0..500]}..." : body warn " Body: #{display_body}" warn " (truncated, full length: #{body.length} characters)" if truncated end |