Class: ContextualLogger::Redactor
- Inherits:
-
Object
- Object
- ContextualLogger::Redactor
- Defined in:
- lib/contextual_logger/redactor.rb
Instance Attribute Summary collapse
-
#redaction_regex ⇒ Object
readonly
Returns the value of attribute redaction_regex.
-
#redaction_set ⇒ Object
readonly
Returns the value of attribute redaction_set.
Instance Method Summary collapse
-
#initialize ⇒ Redactor
constructor
A new instance of Redactor.
- #redact(log_line) ⇒ String
- #register_secret(sensitive_data) ⇒ Object
- #register_secret_regex(regex) ⇒ Object
Constructor Details
#initialize ⇒ Redactor
Returns a new instance of Redactor.
7 8 9 10 |
# File 'lib/contextual_logger/redactor.rb', line 7 def initialize @redaction_set = Set.new @redaction_regex = nil end |
Instance Attribute Details
#redaction_regex ⇒ Object (readonly)
Returns the value of attribute redaction_regex.
5 6 7 |
# File 'lib/contextual_logger/redactor.rb', line 5 def redaction_regex @redaction_regex end |
#redaction_set ⇒ Object (readonly)
Returns the value of attribute redaction_set.
5 6 7 |
# File 'lib/contextual_logger/redactor.rb', line 5 def redaction_set @redaction_set end |
Instance Method Details
#redact(log_line) ⇒ String
26 27 28 29 30 31 32 |
# File 'lib/contextual_logger/redactor.rb', line 26 def redact(log_line) if redaction_regex log_line.gsub(redaction_regex, '<redacted>') else log_line end end |
#register_secret(sensitive_data) ⇒ Object
12 13 14 |
# File 'lib/contextual_logger/redactor.rb', line 12 def register_secret(sensitive_data) register_secret_regex(Regexp.escape(sensitive_data)) end |
#register_secret_regex(regex) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/contextual_logger/redactor.rb', line 16 def register_secret_regex(regex) if redaction_set.add?(regex) @redaction_regex = Regexp.new( redaction_set.to_a.join('|') ) end end |