Log4j 2
  1. Log4j 2
  2. LOG4J2-147

ThreadContextMapFilter doesn't match properly when a single keyvalue is provided

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-beta3
    • Fix Version/s: 2.0-beta4
    • Component/s: Filters
    • Labels:
      None

      Description

      I was testing out a global ThreadContextMapFilter and noticed it wasn't matching properly. I took a closer look at the code and found because it wasn't matching the value to the value on the context but rather the key.

      I changed it to use the value as the argument to equals and this fixed it. Here is the diff of what I am running with.

      diff --git a/core/src/main/java/org/apache/logging/log4j/core/filter/ThreadContextMapFilter.java b/core/src/main/java/org/apache/logging/log4j/core/filter/ThreadContextMapFilter.java
      index 9ad6cab..b3f3838 100644
      — a/core/src/main/java/org/apache/logging/log4j/core/filter/ThreadContextMapFi
      +++ b/core/src/main/java/org/apache/logging/log4j/core/filter/ThreadContextMapFilter.java
      @@ -96,7 +96,7 @@ public class ThreadContextMapFilter extends MapFilter {
      }
      }
      } else

      { - match = key.equals(ThreadContext.get(key)); + match = value.equals(ThreadContext.get(key)); }

      return match ? onMatch : onMismatch;
      }

        Activity

        Hide
        Ralph Goers added a comment -

        Fixed in revision 1434543. Please verify and close.

        Show
        Ralph Goers added a comment - Fixed in revision 1434543. Please verify and close.

          People

          • Assignee:
            Ralph Goers
            Reporter:
            William Burns
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development