Class RedactionProcessor

java.lang.Object
codes.grow.packages.betterstack.logging.RedactionProcessor

public final class RedactionProcessor extends Object
Redacts log records before they are queued.

Attribute names that contain one of the keys (case-insensitive substring) get their whole value replaced, at any depth of nested maps and lists. The patterns replace their matches in the body and in every string attribute value.

  • Field Details

    • DEFAULT_REDACT_KEYS

      public static final List<String> DEFAULT_REDACT_KEYS
      Default sensitive attribute name fragments (SPEC section 4).
    • DEFAULT_REPLACEMENT

      public static final String DEFAULT_REPLACEMENT
      Default replacement text.
      See Also:
  • Method Details

    • defaults

      public static RedactionProcessor defaults()
      Returns a processor with the default keys, no patterns and "[REDACTED]".
      Returns:
      default processor
    • builder

      public static RedactionProcessor.Builder builder()
      Returns a builder with the defaults.
      Returns:
      builder
    • process

      public LogRecord process(LogRecord record)
      Returns a redacted copy of the record.
      Parameters:
      record - the record
      Returns:
      a new, redacted record
    • redactMap

      public Map<String,Object> redactMap(Map<String,?> attributes)
      Redacts an attribute map (same rules as for record attributes).
      Parameters:
      attributes - attributes
      Returns:
      redacted copy
    • isSensitive

      public boolean isSensitive(String name)
      Whether an attribute name matches one of the keys.
      Parameters:
      name - attribute name
      Returns:
      true when the value must be replaced