Makes sense. Sent from my iPhone
> On 2016/04/16, at 23:20, Gary Gregory <[email protected]> wrote: > > Hi, > > The ser+deser sequence feels like something that should be refactored into a > serializedCopy() or deepCopy() method depending on whether or not you want to > publicize the copying technique. > > Gary > > ---------- Forwarded message ---------- > From: <[email protected]> > Date: Apr 16, 2016 5:55 AM > Subject: [3/5] logging-log4j2 git commit: LOG4J2-1334 ListAppender must add > snapshot of MutableLogEvent to the list, not the MutableLogEvent itself > (since it will change) > To: <[email protected]> > Cc: > >> 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/master >> Commit: 3f395f63d03b603ef628e214d3f01dd226793baf >> Parents: 07cd44a >> Author: rpopma <[email protected]> >> Authored: Sat Apr 16 21:41:40 2016 +0900 >> Committer: rpopma <[email protected]> >> 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);
