ppkarwasz commented on issue #3527: URL: https://github.com/apache/logging-log4j2/issues/3527#issuecomment-2713531070
@sundaybluesky, Did you consider using [a custom filter](https://logging.apache.org/log4j/2.x/manual/filters.html) instead? Based on your code all you need is a filter like this: ```java @Plugin(name = "CustomFilter", category = Node.CATEGORY) public class CustomFilter extends AbstractFilter { @PluginFactory public static CustomFilter newFilter( @PluginAttribute("onMatch") Result onMatch, @PluginAttribute("onMismatch") Result onMismatch) { return new CustomFilter(onMatch, onMismatch); } private CustomFilter(Result onMatch, Result onMismatch) { super(onMatch, onMismatch); } private Result filter() { return isCustomEnablementOn ? getOnMatch() : getOnMismatch(); } @Override public Result filter(Logger logger, Level level, Marker marker, Message msg, Throwable t) { return filter(); } @Override public Result filter(Logger logger, Level level, Marker marker, Object msg, Throwable t) { return filter(); } // All other methods except `filter(LogEvent)`, which will not be used. } ``` You can then use it in your configuration: ```xml <Configuration> <CustomFilter onMatch="ACCEPT" onMismatch="NEUTRAL"/> <!-- ... --> <Loggers> <!-- Logger configuration --> </Loggers> </Configuration> ``` See [Filters](https://logging.apache.org/log4j/2.x/manual/filters.html) and [Extending filters](https://logging.apache.org/log4j/2.x/manual/filters.html#extending) for more information on how filters work. In your case the filter will work at [the `Logger` stage](https://logging.apache.org/log4j/2.x/manual/filters.html#logger-stage) and behave exactly like your current code. -- 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