Details
Description
Using Log4J 2.5 with AsyncLogger mode enabled. Filtering events at the Appender level using DynamicThresholdFilter is not working.The filter is basing its decision on the ThreadContext even though it is filtering an asynchronous event on a worker thread.
private Result filter(final Level level) { final Object value = ThreadContext.get(key); // always returns null, ThreadContext is empty on disruptor thread if (value != null) { …
Fixing the DynamicThresholdFilter to use the context from the log event instead produces the expected filtering behavior :
private Result filter(final Level level, Map<String, String> context) { final Object value = context.get(key); if (value != null) { … public Result filter(final LogEvent event) { return filter(event.getLevel(), event.getContextMap()); } public Result filter(final Logger logger, final Level level, final Marker marker, final Message msg, final Throwable t) { return filter(level, ThreadContext.getContext()); }
ThreadContextMapFilter is built the same way.