Class RegexFilter

All Implemented Interfaces:
Filter, LifeCycle, LifeCycle2

@Plugin(name="RegexFilter", category="Core", elementType="filter", printObject=true) @NullMarked public final class RegexFilter extends AbstractFilter
This filter returns the onMatch result if the message exactly matches the configured "regex" regular-expression pattern; otherwise, it returns the onMismatch result.
  • Method Details

    • getPattern

      public Pattern getPattern()
      Returns the compiled regular-expression pattern.
      Returns:
      the pattern (will never be null
      Since:
      2.27.0
    • getRegex

      public String getRegex()
      Returns the regular-expression.
      Returns:
      the regular-expression (it may be an empty string but never null)
      Since:
      2.27.0
    • isUseRawMessage

      public boolean isUseRawMessage()
      Returns whether the raw-message should be used.
      Returns:
      true if the raw message should be used; otherwise, false
      Since:
      2.27.0
    • filter

      public Filter.Result filter(@Nullable Logger logger, @Nullable Level level, @Nullable Marker marker, @Nullable String msg, @Nullable Object @Nullable ... params)
      Appender Filter method. The default returns NEUTRAL.

      This implementation performs the filter evaluation against the given message formatted with the given parameters.

      The following method arguments are ignored by this filter method implementation:

      • logger
      • level
      • marker

      Specified by:
      filter in interface Filter
      Overrides:
      filter in class AbstractFilter
      Parameters:
      logger - the Logger.
      level - The logging Level.
      marker - The Marker, if any.
      msg - The message, if present.
      params - An array of parameters or null.
      Returns:
      The Result of filtering.
    • filter

      public Filter.Result filter(@Nullable Logger logger, @Nullable Level level, @Nullable Marker marker, @Nullable Object message, @Nullable Throwable throwable)
      Appender Filter method. The default returns NEUTRAL.

      This implementation performs the filter evaluation against the given message.

      The following method arguments are ignored by this filter method implementation:

      • logger
      • level
      • marker
      • throwable

      Specified by:
      filter in interface Filter
      Overrides:
      filter in class AbstractFilter
      Parameters:
      logger - the Logger.
      level - The logging Level.
      marker - The Marker, if any.
      message - The message, if present.
      throwable - A throwable or null.
      Returns:
      The Result of filtering.
    • filter

      public Filter.Result filter(@Nullable Logger logger, @Nullable Level level, @Nullable Marker marker, @Nullable Message message, @Nullable Throwable throwable)
      Appender Filter method. The default returns NEUTRAL.

      This implementation performs the filter evaluation against the given message.

      The following method arguments are ignored by this filter method implementation:

      • logger
      • level
      • marker
      • throwable

      Specified by:
      filter in interface Filter
      Overrides:
      filter in class AbstractFilter
      Parameters:
      logger - the Logger.
      level - The logging Level.
      marker - The Marker, if any.
      message - The message, if present.
      throwable - A throwable or null.
      Returns:
      The Result of filtering.
    • filter

      public Filter.Result filter(LogEvent event)
      Context Filter method. The default returns NEUTRAL.
      Specified by:
      filter in interface Filter
      Overrides:
      filter in class AbstractFilter
      Parameters:
      event - The LogEvent.
      Returns:
      The Result of filtering.
      Throws:
      NullPointerException - if the event argument is null
    • toString

      public String toString()
      Overrides:
      toString in class AbstractFilter
    • newBuilder

      @PluginBuilderFactory public static RegexFilter.Builder newBuilder()
      Creates a new builder instance.
      Returns:
      the new builder instance
      Since:
      2.27.0
    • createFilter

      @Deprecated public static RegexFilter createFilter(@PluginAttribute("regex") String regex, String @Nullable [] patternFlags, @PluginAttribute("useRawMsg") @Nullable Boolean useRawMsg, @PluginAttribute("onMatch") @Nullable Filter.Result match, @PluginAttribute("onMismatch") @Nullable Filter.Result mismatch) throws IllegalArgumentException, IllegalAccessException
      Deprecated.
      use newBuilder() to instantiate builder
      Creates a Filter that matches a regular expression.
      Parameters:
      regex - The regular expression to match.
      patternFlags - Ignored, kept for backward compatibility.
      useRawMsg - If true, for ParameterizedMessage, StringFormattedMessage, and MessageFormatMessage, the message format pattern; for StructuredDataMessage, the message field will be used as the match target.
      match - The action to perform when a match occurs.
      mismatch - The action to perform when a mismatch occurs.
      Returns:
      The RegexFilter.
      Throws:
      IllegalAccessException - When there is no access to the definition of the specified member.
      IllegalArgumentException - When passed an illegal or inappropriate argument.