vy commented on code in PR #3510: URL: https://github.com/apache/logging-log4j2/pull/3510#discussion_r1977412636
########## log4j-core/src/main/java/org/apache/logging/log4j/core/filter/StringMatchFilter.java: ########## @@ -26,232 +27,551 @@ import org.apache.logging.log4j.plugins.Plugin; import org.apache.logging.log4j.plugins.PluginBuilderAttribute; import org.apache.logging.log4j.plugins.PluginFactory; +import org.apache.logging.log4j.plugins.util.Assert; +import org.apache.logging.log4j.plugins.validation.constraints.Required; import org.apache.logging.log4j.util.PerformanceSensitive; +import org.apache.logging.log4j.util.Strings; +import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.Nullable; /** - * This filter returns the onMatch result if the message in the event matches the specified text - * exactly. + * This filter returns the {@code onMatch} result if the formatted message contains the + * configured "{@code text}" value; otherwise, it returns the {@code onMismatch} result. + * <p> + * The text comparison is case-sensitive. + * </p> */ @Configurable(elementType = Filter.ELEMENT_TYPE, printObject = true) +@NullMarked @Plugin @PerformanceSensitive("allocation") public final class StringMatchFilter extends AbstractFilter { - public static final String ATTR_MATCH = "match"; + /** The string match text. */ private final String text; - private StringMatchFilter(final String text, final Result onMatch, final Result onMismatch) { - super(onMatch, onMismatch); - this.text = text; + /** + * Constructs a new string-match filter instance. + * + * @param builder the builder implementation + * @throws IllegalArgumentException if the {@code text} argument is {@code null} or blank + */ + private StringMatchFilter(final Builder builder) { + + super(builder); + + if (Strings.isNotEmpty(builder.text)) { + this.text = builder.text; + } else { + throw new IllegalArgumentException("The 'text' argument must not be null or empty."); + } } - @Override - public Result filter( - final Logger logger, final Level level, final Marker marker, final String msg, final Object... params) { - return filter(logger.getMessageFactory().newMessage(msg, params).getFormattedMessage()); + /** + * Returns the string-filter match text + * @return the match text + */ + public String getText() { + return this.text; } + /** + * {@inheritDoc} + * <p> + * This implementation performs the filter evaluation on the given event's formatted message. + * </p> + * + * @throws NullPointerException if the given {@code event} is {@code null} + */ @Override - public Result filter( - final Logger logger, final Level level, final Marker marker, final Object msg, final Throwable t) { - return filter(logger.getMessageFactory().newMessage(msg).getFormattedMessage()); + public Result filter(final LogEvent event) { + Objects.requireNonNull(event, "The 'event' argument must not be null."); + return filter(event.getMessage().getFormattedMessage()); Review Comment: Agreed with @ppkarwasz. Please strive to avoid cosmetic changes on the existing code in PRs. Feel free to submit a follow-up PR/commit for these kind of changes. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org