LOG4J2-1447 delegate instantiation of MutableContextData to factory
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/bdba4691 Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/bdba4691 Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/bdba4691 Branch: refs/heads/LOG4J2-1010&LOG4J2-1447-injectable-contextdata&better-datastructure Commit: bdba4691637e48e4144d52507ba0cbfc4a590c89 Parents: 9d88e81 Author: rpopma <rpo...@apache.org> Authored: Fri Aug 12 21:32:37 2016 +0900 Committer: rpopma <rpo...@apache.org> Committed: Fri Aug 12 21:32:37 2016 +0900 ---------------------------------------------------------------------- .../db/jpa/converter/ContextDataJsonAttributeConverter.java | 5 +++-- .../log4j/core/jackson/ContextDataAsEntryListDeserializer.java | 4 ++-- .../logging/log4j/core/jackson/ContextDataDeserializer.java | 4 ++-- .../org/apache/logging/log4j/core/layout/LogEventFixtures.java | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bdba4691/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/ContextDataJsonAttributeConverter.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/ContextDataJsonAttributeConverter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/ContextDataJsonAttributeConverter.java index 93f339d..8285a66 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/ContextDataJsonAttributeConverter.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/ContextDataJsonAttributeConverter.java @@ -24,7 +24,8 @@ import javax.persistence.Converter; import javax.persistence.PersistenceException; import org.apache.logging.log4j.core.ContextData; -import org.apache.logging.log4j.core.impl.ArrayContextData; +import org.apache.logging.log4j.core.impl.ContextDataFactory; +import org.apache.logging.log4j.core.impl.MutableContextData; import org.apache.logging.log4j.core.util.BiConsumer; import org.apache.logging.log4j.util.Strings; @@ -73,7 +74,7 @@ public class ContextDataJsonAttributeConverter implements AttributeConverter<Con return null; } try { - final ArrayContextData result = new ArrayContextData(); + final MutableContextData result = ContextDataFactory.getContextData(); final ObjectNode root = (ObjectNode) OBJECT_MAPPER.readTree(s); final Iterator<Map.Entry<String, JsonNode>> entries = root.fields(); while (entries.hasNext()) { http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bdba4691/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ContextDataAsEntryListDeserializer.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ContextDataAsEntryListDeserializer.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ContextDataAsEntryListDeserializer.java index 6ae28ec..90fe08d 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ContextDataAsEntryListDeserializer.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ContextDataAsEntryListDeserializer.java @@ -20,7 +20,7 @@ import java.io.IOException; import java.util.List; import java.util.Map; -import org.apache.logging.log4j.core.impl.ArrayContextData; +import org.apache.logging.log4j.core.impl.ContextDataFactory; import org.apache.logging.log4j.core.impl.MutableContextData; import com.fasterxml.jackson.core.JsonParser; @@ -48,7 +48,7 @@ public class ContextDataAsEntryListDeserializer extends StdDeserializer<MutableC final List<MapEntry> list = jp.readValueAs(new TypeReference<List<MapEntry>>() { // empty }); - final MutableContextData contextData = new ArrayContextData(list.size()); + final MutableContextData contextData = new ContextDataFactory().getContextData(); for (final MapEntry mapEntry : list) { contextData.putValue(mapEntry.getKey(), mapEntry.getValue()); } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bdba4691/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ContextDataDeserializer.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ContextDataDeserializer.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ContextDataDeserializer.java index b6e7041..e17b9a4 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ContextDataDeserializer.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ContextDataDeserializer.java @@ -20,7 +20,7 @@ package org.apache.logging.log4j.core.jackson; import java.io.IOException; import java.util.Map; -import org.apache.logging.log4j.core.impl.ArrayContextData; +import org.apache.logging.log4j.core.impl.ContextDataFactory; import org.apache.logging.log4j.core.impl.MutableContextData; import com.fasterxml.jackson.core.JsonParser; @@ -51,7 +51,7 @@ public class ContextDataDeserializer extends StdDeserializer<MutableContextData> // if (tok != JsonToken.START_OBJECT) { // throw new IOException("Expected data to start with an Object"); // } - final MutableContextData contextData = new ArrayContextData(); + final MutableContextData contextData = ContextDataFactory.getContextData(); // Iterate over object fields: while (jp.nextToken() != JsonToken.END_OBJECT) { String fieldName = jp.getCurrentName(); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bdba4691/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/LogEventFixtures.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/LogEventFixtures.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/LogEventFixtures.java index f210bca..7ce4e6c 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/LogEventFixtures.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/LogEventFixtures.java @@ -25,7 +25,7 @@ import org.apache.logging.log4j.Level; import org.apache.logging.log4j.Marker; import org.apache.logging.log4j.MarkerManager; import org.apache.logging.log4j.core.LogEvent; -import org.apache.logging.log4j.core.impl.ArrayContextData; +import org.apache.logging.log4j.core.impl.ContextDataFactory; import org.apache.logging.log4j.core.impl.Log4jLogEvent; import org.apache.logging.log4j.core.impl.ThrowableProxy; import org.apache.logging.log4j.message.SimpleMessage; @@ -84,7 +84,7 @@ class LogEventFixtures { static void assertEqualLogEvents(final LogEvent expected, final LogEvent actual, final boolean includeSource, final boolean includeContext) { assertEquals(expected.getClass(), actual.getClass()); - assertEquals(includeContext ? expected.getContextData() : new ArrayContextData(), actual.getContextData()); + assertEquals(includeContext ? expected.getContextData() : ContextDataFactory.getContextData(), actual.getContextData()); assertEquals(includeContext ? expected.getContextMap() : Collections.EMPTY_MAP, actual.getContextMap()); assertEquals(expected.getContextStack(), actual.getContextStack()); assertEquals(expected.getLevel(), actual.getLevel());