LOG4J2-1342 added implementation of new method #memento(), ensure internal parameters field is not null
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/710c34d6 Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/710c34d6 Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/710c34d6 Branch: refs/heads/LOG4j2-494 Commit: 710c34d6cc4332b351ab818b0e1240b92613f26a Parents: 185dce2 Author: rpopma <[email protected]> Authored: Fri Apr 22 14:38:04 2016 +0900 Committer: Ralph Goers <[email protected]> Committed: Mon Apr 25 21:30:29 2016 -0700 ---------------------------------------------------------------------- .../logging/log4j/core/impl/MutableLogEvent.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/710c34d6/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java index e256723..7fd31c0 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java @@ -27,6 +27,7 @@ import org.apache.logging.log4j.ThreadContext; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.util.Constants; import org.apache.logging.log4j.message.Message; +import org.apache.logging.log4j.message.ParameterizedMessage; import org.apache.logging.log4j.message.ReusableMessage; import org.apache.logging.log4j.message.SimpleMessage; import org.apache.logging.log4j.util.Strings; @@ -60,10 +61,11 @@ public class MutableLogEvent implements LogEvent, ReusableMessage { private ThreadContext.ContextStack contextStack; public MutableLogEvent() { - this(null); + this(new StringBuilder(Constants.INITIAL_REUSABLE_MESSAGE_SIZE), new Object[10]); } - public MutableLogEvent(final Object[] replacementParameters) { + public MutableLogEvent(final StringBuilder msgText, final Object[] replacementParameters) { + this.messageText = msgText; this.parameters = replacementParameters; } @@ -273,6 +275,15 @@ public class MutableLogEvent implements LogEvent, ReusableMessage { } @Override + public Message memento() { + if (message != null) { + return message; + } + Object[] params = parameters == null ? new Object[0] : Arrays.copyOf(parameters, parameterCount); + return new ParameterizedMessage(messageText.toString(), params); + } + + @Override public Throwable getThrown() { return thrown; }
