You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2016/11/08 16:30:06 UTC

logging-log4j2 git commit: LOG4J2-1677 Completes the work to make MapFilter garbage-free; call MapMessage::getDataValue to avoid calling MapMessage::getData (which allocates)

Repository: logging-log4j2
Updated Branches:
  refs/heads/master e84c452f6 -> 171f9a328


LOG4J2-1677 Completes the work to make MapFilter garbage-free; call MapMessage::getDataValue to avoid calling MapMessage::getData (which allocates)


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/171f9a32
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/171f9a32
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/171f9a32

Branch: refs/heads/master
Commit: 171f9a328508d432a9fac2a949312fcc5b974738
Parents: e84c452
Author: rpopma <rp...@apache.org>
Authored: Wed Nov 9 01:29:56 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Wed Nov 9 01:29:56 2016 +0900

----------------------------------------------------------------------
 .../logging/log4j/core/filter/MapFilter.java      | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/171f9a32/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/MapFilter.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/MapFilter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/MapFilter.java
index e760512..f856a2d 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/MapFilter.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/MapFilter.java
@@ -39,7 +39,6 @@ import org.apache.logging.log4j.util.BiConsumer;
 import org.apache.logging.log4j.util.PerformanceSensitive;
 import org.apache.logging.log4j.util.ReadOnlyStringMap;
 import org.apache.logging.log4j.util.SortedArrayStringMap;
-import org.apache.logging.log4j.util.StringMap;
 
 /**
  * A Filter that operates on a Map.
@@ -67,7 +66,7 @@ public class MapFilter extends AbstractFilter {
     public Result filter(final Logger logger, final Level level, final Marker marker, final Message msg,
                          final Throwable t) {
         if (msg instanceof MapMessage) {
-            return filter(((MapMessage) msg).getData()) ? onMatch : onMismatch;
+            return filter((MapMessage) msg) ? onMatch : onMismatch;
         }
         return Result.NEUTRAL;
     }
@@ -76,11 +75,24 @@ public class MapFilter extends AbstractFilter {
     public Result filter(final LogEvent event) {
         final Message msg = event.getMessage();
         if (msg instanceof MapMessage) {
-            return filter(((MapMessage) msg).getData()) ? onMatch : onMismatch;
+            return filter((MapMessage) msg) ? onMatch : onMismatch;
         }
         return Result.NEUTRAL;
     }
 
+    protected boolean filter(final MapMessage mapMessage) {
+        boolean match = false;
+        for (int i = 0; i < map.size(); i++) {
+            final String toMatch = mapMessage.getDataValue(map.getKeyAt(i));
+            match = toMatch != null && ((List<String>) map.getValueAt(i)).contains(toMatch);
+
+            if ((!isAnd && match) || (isAnd && !match)) {
+                break;
+            }
+        }
+        return match;
+    }
+
     protected boolean filter(final Map<String, String> data) {
         boolean match = false;
         for (int i = 0; i < map.size(); i++) {