Class RegexValueMasker

java.lang.Object
net.logstash.logback.mask.RegexValueMasker
All Implemented Interfaces:
ValueMasker

public class RegexValueMasker extends Object implements ValueMasker
Masks values based on a regular expression.
  • Constructor Details

    • RegexValueMasker

      public RegexValueMasker(String regex, Object mask)
      Parameters:
      regex - the regex used to identify values to mask
      mask - the value to write for values that match the regex (can contain back references to capture groups in the regex)
    • RegexValueMasker

      public RegexValueMasker(Pattern pattern, Object mask)
      Parameters:
      pattern - the pattern used to identify values to mask
      mask - the value to write for values that match the regex (can contain back references to capture groups in the regex)
  • Method Details

    • mask

      public Object mask(JsonStreamContext context, Object o)
      Description copied from interface: ValueMasker
      If the given value at the JSON stream context's current path should be masked, then returns the masked value to write as the value.. The MaskingJsonGenerator will write the returned masked value as the value (instead of the original value).

      If the given value at the JSON stream context's current path should NOT be masked, returns null.

      Specified by:
      mask in interface ValueMasker
      Parameters:
      context - the current JSON stream context, which can be used to determine the path within the JSON output. (could be at a field value path or an array element value path)
      o - the number or string scalar value to potentially mask (could be a field value or an array element value).
      Returns:
      A non-null masked value to write if given value at the JSON stream context's current path should be masked. Otherwise null if the given value at the JSON stream context's current path should NOT be masked. To write a JSON null value as the masked value, return NullNode.instance. To write "****", the return MaskingJsonGenerator.MASK