Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-1258

Async DynamicThresholdFilter does not use the log event's context map

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 2.5
    • 2.6
    • Filters
    • -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector

    • Patch

    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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            fralalonde Francis Lalonde
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 24h
                24h
                Remaining:
                Remaining Estimate - 24h
                24h
                Logged:
                Time Spent - Not Specified
                Not Specified