Class: Lumberjack::Formatter::RedactFormatter
- Inherits:
-
Object
- Object
- Lumberjack::Formatter::RedactFormatter
- Defined in:
- lib/lumberjack/formatter/redact_formatter.rb
Overview
Log sensitive information in a redacted format showing the first and last characters of the value, with the rest replaced by asterisks. The number of characters shown is dependent on the length of the value; short values will not show any characters in order to avoid revealing too much information.
This formatter is useful for logging sensitive data while still providing enough context to distinguish between different values during debugging.
Instance Method Summary collapse
-
#call(obj) ⇒ String, Object
Redact a string value by showing only the first and last characters.
Instance Method Details
#call(obj) ⇒ String, Object
Redact a string value by showing only the first and last characters.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/lumberjack/formatter/redact_formatter.rb', line 25 def call(obj) return obj unless obj.is_a?(String) if obj.length > 8 "#{obj[0..1]}#{"*" * (obj.length - 4)}#{obj[-2..]}" elsif obj.length > 5 "#{obj[0]}#{"*" * (obj.length - 2)}#{obj[-1]}" else "*****" end end |