Class: Broadcast::DebugLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/broadcast/debug_logger.rb

Overview

Debug logging for HTTP traffic, kept separate from Connection so the redaction rules live in one obvious place.

Request bodies routinely carry SMTP passwords and provider API keys (email server create/update), so nothing is logged verbatim — matching keys are replaced before the body is serialized.

Constant Summary collapse

SENSITIVE_KEYS =
%w[
  smtp_password aws_access_key_id aws_secret_access_key
  outbound_aws_access_key_id outbound_aws_secret_access_key
  postmark_api_token inboxroad_api_token smtp_com_api_key
  api_key api_token password secret
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ DebugLogger

Returns a new instance of DebugLogger.



20
21
22
# File 'lib/broadcast/debug_logger.rb', line 20

def initialize(config)
  @config = config
end

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/broadcast/debug_logger.rb', line 24

def enabled?
  @config.debug && !@config.logger.nil?
end

#request(http_request, body) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/broadcast/debug_logger.rb', line 28

def request(http_request, body)
  return unless enabled?

  @config.logger.debug("[Broadcast] #{http_request.method} #{http_request.uri}")
  return unless body.is_a?(Hash) && body.any?

  @config.logger.debug("[Broadcast] Body: #{redact(body).to_json}")
end

#response(http_response) ⇒ Object



37
38
39
40
41
# File 'lib/broadcast/debug_logger.rb', line 37

def response(http_response)
  return unless enabled?

  @config.logger.debug("[Broadcast] Response: #{http_response.code} #{http_response.body}")
end

#warnings(warnings) ⇒ Object



43
44
45
46
47
# File 'lib/broadcast/debug_logger.rb', line 43

def warnings(warnings)
  return unless @config.logger

  warnings.each { |warning| @config.logger.warn("[Broadcast] #{warning}") }
end