class ContextualLogger::Redactor

Attributes

redaction_regex[R]
redaction_set[R]

Public Class Methods

new() click to toggle source
# File lib/contextual_logger/redactor.rb, line 7
def initialize
  @redaction_set   = Set.new
  @redaction_regex = nil
end

Public Instance Methods

redact(log_line) click to toggle source
# File lib/contextual_logger/redactor.rb, line 20
def redact(log_line)
  if redaction_regex
    log_line.gsub(redaction_regex, '<redacted>')
  else
    log_line
  end
end
register_secret(sensitive_data) click to toggle source
# File lib/contextual_logger/redactor.rb, line 12
def register_secret(sensitive_data)
  if redaction_set.add?(Regexp.escape(sensitive_data))
    @redaction_regex = Regexp.new(
      redaction_set.to_a.join('|')
    )
  end
end