You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by mi...@apache.org on 2016/04/18 13:37:53 UTC

[07/50] logging-log4j2 git commit: LOG4J2-1334 ListAppender must add snapshot of MutableLogEvent to the list, not the MutableLogEvent itself (since it will change)

LOG4J2-1334 ListAppender must add snapshot of MutableLogEvent to the list, not the MutableLogEvent itself (since it will change)


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

Branch: refs/heads/LOG4J2-1365
Commit: 3f395f63d03b603ef628e214d3f01dd226793baf
Parents: 07cd44a
Author: rpopma <rp...@apache.org>
Authored: Sat Apr 16 21:41:40 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sat Apr 16 21:41:40 2016 +0900

----------------------------------------------------------------------
 .../apache/logging/log4j/test/appender/ListAppender.java    | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3f395f63/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java b/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
index 97ca15d..19aeaee 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
@@ -31,6 +31,8 @@ import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
 import org.apache.logging.log4j.core.config.plugins.PluginElement;
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
 import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.apache.logging.log4j.core.impl.MutableLogEvent;
 import org.apache.logging.log4j.core.layout.SerializedLayout;
 
 /**
@@ -81,7 +83,12 @@ public class ListAppender extends AbstractAppender {
     public synchronized void append(final LogEvent event) {
         final Layout<? extends Serializable> layout = getLayout();
         if (layout == null) {
-            events.add(event);
+            if (event instanceof MutableLogEvent) {
+                // must take snapshot or subsequent calls to logger.log() will modify this event
+                events.add(Log4jLogEvent.deserialize(Log4jLogEvent.serialize(event, event.isIncludeLocation())));
+            } else {
+                events.add(event);
+            }
         } else if (layout instanceof SerializedLayout) {
             final byte[] header = layout.getHeader();
             final byte[] content = layout.toByteArray(event);