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/04/22 07:58:35 UTC
[01/15] logging-log4j2 git commit: LOG4J2-1342 added tests to verify
parameters are passed correctly with async logging
Repository: logging-log4j2
Updated Branches:
refs/heads/master 825facd64 -> 61da5dc91
LOG4J2-1342 added tests to verify parameters are passed correctly with async logging
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/8b09f294
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/8b09f294
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/8b09f294
Branch: refs/heads/master
Commit: 8b09f294a2a4ac962b234951f26fd66141dd59d6
Parents: 395d409
Author: rpopma <rp...@apache.org>
Authored: Fri Apr 22 12:08:38 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Apr 22 12:08:38 2016 +0900
----------------------------------------------------------------------
.../layout/CsvParameterLayoutAllAsyncTest.java | 69 ++++++++++++++++++
.../core/layout/CsvParameterLayoutTest.java | 73 ++++++++++++--------
.../src/test/resources/csvParamsMixedAsync.xml | 13 ++++
log4j-core/src/test/resources/csvParamsSync.xml | 29 ++++++++
4 files changed, 156 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8b09f294/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/CsvParameterLayoutAllAsyncTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/CsvParameterLayoutAllAsyncTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/CsvParameterLayoutAllAsyncTest.java
new file mode 100644
index 0000000..0ef2e1d
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/CsvParameterLayoutAllAsyncTest.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.core.layout;
+
+import org.apache.commons.csv.CSVFormat;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.core.Logger;
+import org.apache.logging.log4j.core.async.AsyncLoggerContextSelector;
+import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.apache.logging.log4j.core.util.Constants;
+import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.apache.logging.log4j.util.Strings;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Tests {@link AbstractCsvLayout} with all loggers async.
+ *
+ * @since 2.6
+ */
+public class CsvParameterLayoutAllAsyncTest {
+
+ @BeforeClass
+ public static void beforeClass() {
+ System.setProperty(Constants.LOG4J_CONTEXT_SELECTOR,
+ AsyncLoggerContextSelector.class.getName());
+ System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY,
+ "AsyncLoggerTest.xml");
+ }
+
+ @AfterClass
+ public static void afterClass() {
+ System.setProperty(Constants.LOG4J_CONTEXT_SELECTOR, Strings.EMPTY);
+ }
+
+
+ @Test
+ public void testLayoutDefaultNormal() throws Exception {
+ Logger root = (Logger) LogManager.getRootLogger();
+ CsvParameterLayoutTest.testLayoutNormalApi(root, CsvParameterLayout.createDefaultLayout(), false);
+ }
+
+ @Test
+ public void testLayoutDefaultObjectArrayMessage() throws Exception {
+ Logger root = (Logger) LogManager.getRootLogger();
+ CsvParameterLayoutTest.testLayoutNormalApi(root, CsvParameterLayout.createDefaultLayout(), true);
+ }
+
+ @Test
+ public void testLayoutTab() throws Exception {
+ Logger root = (Logger) LogManager.getRootLogger();
+ CsvParameterLayoutTest.testLayoutNormalApi(root, CsvParameterLayout.createLayout(CSVFormat.TDF), true);
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8b09f294/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/CsvParameterLayoutTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/CsvParameterLayoutTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/CsvParameterLayoutTest.java
index 5f58d79..ce3abfc 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/CsvParameterLayoutTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/CsvParameterLayoutTest.java
@@ -16,9 +16,9 @@
*/
package org.apache.logging.log4j.core.layout;
-import static org.junit.Assert.assertEquals;
-
import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -26,43 +26,49 @@ import org.apache.commons.csv.CSVFormat;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.ThreadContext;
import org.apache.logging.log4j.core.Appender;
-import org.apache.logging.log4j.core.BasicConfigurationFactory;
import org.apache.logging.log4j.core.Logger;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.apache.logging.log4j.junit.LoggerContextRule;
import org.apache.logging.log4j.message.ObjectArrayMessage;
import org.apache.logging.log4j.test.appender.ListAppender;
import org.junit.AfterClass;
import org.junit.Assert;
-import org.junit.BeforeClass;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static org.junit.Assert.*;
/**
* Tests {@link AbstractCsvLayout}.
*
* @since 2.4
*/
+@RunWith(value = Parameterized.class)
public class CsvParameterLayoutTest {
- static ConfigurationFactory cf = new BasicConfigurationFactory();
+ @Parameterized.Parameters(name = "{0}")
+ public static Collection<Object[]> data() {
+ return Arrays.asList(
+ new Object[][]{
+ { new LoggerContextRule("csvParamsSync.xml"), },
+ { new LoggerContextRule("csvParamsMixedAsync.xml"), },
+ }
+ );
+ }
- @AfterClass
- public static void cleanupClass() {
- ConfigurationFactory.removeConfigurationFactory(cf);
- ThreadContext.clearAll();
+ @Rule
+ public final LoggerContextRule init;
+
+ public CsvParameterLayoutTest(final LoggerContextRule contextRule) {
+ this.init = contextRule;
}
- @BeforeClass
- public static void setupClass() {
+ @AfterClass
+ public static void cleanupClass() {
+// System.setProperty(Constants.LOG4J_CONTEXT_SELECTOR, null);
ThreadContext.clearAll();
- ConfigurationFactory.setConfigurationFactory(cf);
- final LoggerContext ctx = LoggerContext.getContext();
- ctx.reconfigure();
}
- private final LoggerContext ctx = LoggerContext.getContext();
-
- private final Logger root = ctx.getLogger("");
-
@Test
public void testCustomCharset() {
final AbstractCsvLayout layout = CsvParameterLayout.createLayout(null, "Excel", null, null, null, null, null,
@@ -82,7 +88,7 @@ public class CsvParameterLayoutTest {
assertEquals("text/csv; charset=UTF-8", layout.getContentType());
}
- private void testLayoutNormalApi(final AbstractCsvLayout layout, boolean messageApi) throws Exception {
+ static void testLayoutNormalApi(final Logger root, final AbstractCsvLayout layout, boolean messageApi) throws Exception {
final Map<String, Appender> appenders = root.getAppenders();
for (final Appender appender : appenders.values()) {
root.removeAppender(appender);
@@ -97,11 +103,19 @@ public class CsvParameterLayoutTest {
// output messages
if (messageApi) {
- logDebugObjectArrayMessage();
+ logDebugObjectArrayMessage(root);
} else {
- logDebugNormalApi();
+ logDebugNormalApi(root);
+ }
+
+ // wait until background thread finished processing
+ int maxTries = 50;
+ while (appender.getMessages().size() < 4 && maxTries-- > 0) {
+ Thread.sleep(1L);
}
+ assertEquals("Background thread did not finish processing: msg count", 4, appender.getMessages().size());
+ // don't stop appender until background thread is done
appender.stop();
final List<String> list = appender.getMessages();
@@ -112,14 +126,14 @@ public class CsvParameterLayoutTest {
Assert.assertEquals("7" + d + "8" + d + "9" + d + "10", list.get(3));
}
- private void logDebugNormalApi() {
+ private static void logDebugNormalApi(final Logger root) {
root.debug("with placeholders: {}{}{}", 1, 2, 3);
root.debug("without placeholders", 2, 3);
root.debug(null, 5, 6);
root.debug("invalid placeholder count {}", 7, 8, 9, 10);
}
- private void logDebugObjectArrayMessage() {
+ private static void logDebugObjectArrayMessage(final Logger root) {
root.debug(new ObjectArrayMessage(1, 2, 3));
root.debug(new ObjectArrayMessage(2, 3));
root.debug(new ObjectArrayMessage(5, 6));
@@ -128,16 +142,19 @@ public class CsvParameterLayoutTest {
@Test
public void testLayoutDefaultNormal() throws Exception {
- testLayoutNormalApi(CsvParameterLayout.createDefaultLayout(), false);
+ Logger root = this.init.getLogger("");
+ testLayoutNormalApi(root, CsvParameterLayout.createDefaultLayout(), false);
}
@Test
public void testLayoutDefaultObjectArrayMessage() throws Exception {
- testLayoutNormalApi(CsvParameterLayout.createDefaultLayout(), true);
+ Logger root = this.init.getLogger("");
+ testLayoutNormalApi(root, CsvParameterLayout.createDefaultLayout(), true);
}
@Test
public void testLayoutTab() throws Exception {
- testLayoutNormalApi(CsvParameterLayout.createLayout(CSVFormat.TDF), true);
+ Logger root = this.init.getLogger("");
+ testLayoutNormalApi(root, CsvParameterLayout.createLayout(CSVFormat.TDF), true);
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8b09f294/log4j-core/src/test/resources/csvParamsMixedAsync.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/csvParamsMixedAsync.xml b/log4j-core/src/test/resources/csvParamsMixedAsync.xml
new file mode 100644
index 0000000..4d0811a
--- /dev/null
+++ b/log4j-core/src/test/resources/csvParamsMixedAsync.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Configuration status="OFF">
+ <Appenders>
+ <List name="List">
+ <PatternLayout pattern="[%-5level] %c{1.} %msg%n" />
+ </List>
+ </Appenders>
+ <Loggers>
+ <AsyncRoot level="debug" includeLocation="false">
+ <appender-ref ref="List"/>
+ </AsyncRoot>
+ </Loggers>
+</Configuration>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8b09f294/log4j-core/src/test/resources/csvParamsSync.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/csvParamsSync.xml b/log4j-core/src/test/resources/csvParamsSync.xml
new file mode 100644
index 0000000..c2a92c3
--- /dev/null
+++ b/log4j-core/src/test/resources/csvParamsSync.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<Configuration status="WARN">
+ <Appenders>
+ <List name="List">
+ <PatternLayout pattern="[%-5level] %c{1.} %msg%n" />
+ </List>
+ </Appenders>
+ <Loggers>
+ <Root level="debug">
+ <AppenderRef ref="List" />
+ </Root>
+ </Loggers>
+</Configuration>
\ No newline at end of file
[10/15] logging-log4j2 git commit: LOG4J2-1342 added implementation
of new method #memento(), ensure internal parameters field is not null
Posted by rp...@apache.org.
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/ba8d2905
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/ba8d2905
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/ba8d2905
Branch: refs/heads/master
Commit: ba8d2905afaaa9355c9f20afd36d2169a9f25db9
Parents: f34a555
Author: rpopma <rp...@apache.org>
Authored: Fri Apr 22 14:38:04 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Apr 22 14:38:04 2016 +0900
----------------------------------------------------------------------
.../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/ba8d2905/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;
}
[14/15] logging-log4j2 git commit: LOG4J2-1334 enable unit tests that
verify that synchronous logging and mixed sync/async is garbage-free
Posted by rp...@apache.org.
LOG4J2-1334 enable unit tests that verify that synchronous logging and mixed sync/async is garbage-free
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/d1d98558
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/d1d98558
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/d1d98558
Branch: refs/heads/master
Commit: d1d985585d5a30dff821aadbb2e56b1aa310f713
Parents: c0459ff
Author: rpopma <rp...@apache.org>
Authored: Fri Apr 22 14:54:53 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Apr 22 14:54:53 2016 +0900
----------------------------------------------------------------------
.../apache/logging/log4j/core/GcFreeMixedSyncAyncLoggingTest.java | 2 --
.../apache/logging/log4j/core/GcFreeSynchronousLoggingTest.java | 2 --
2 files changed, 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d1d98558/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeMixedSyncAyncLoggingTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeMixedSyncAyncLoggingTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeMixedSyncAyncLoggingTest.java
index b917f93..c18861b 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeMixedSyncAyncLoggingTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeMixedSyncAyncLoggingTest.java
@@ -26,8 +26,6 @@ import org.junit.Test;
*/
public class GcFreeMixedSyncAyncLoggingTest {
- // Ignore until mixed synchronous/asynchronous logging is gc-free
- @Ignore
@Test
public void testNoAllocationDuringSteadyStateLogging() throws Throwable {
GcFreeLoggingTestUtil.runTest(getClass());
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d1d98558/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeSynchronousLoggingTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeSynchronousLoggingTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeSynchronousLoggingTest.java
index 9a01c22..731c2af 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeSynchronousLoggingTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeSynchronousLoggingTest.java
@@ -26,8 +26,6 @@ import org.junit.Test;
*/
public class GcFreeSynchronousLoggingTest {
- // Ignore until synchronous logging is gc-free
- @Ignore
@Test
public void testNoAllocationDuringSteadyStateLogging() throws Throwable {
GcFreeLoggingTestUtil.runTest(getClass());
[15/15] logging-log4j2 git commit: Merge remote-tracking branch
'origin/master'
Posted by rp...@apache.org.
Merge remote-tracking branch 'origin/master'
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/61da5dc9
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/61da5dc9
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/61da5dc9
Branch: refs/heads/master
Commit: 61da5dc91a4166c4c1cba2461461da407b7d9e08
Parents: d1d9855 825facd
Author: rpopma <rp...@apache.org>
Authored: Fri Apr 22 14:58:41 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Apr 22 14:58:41 2016 +0900
----------------------------------------------------------------------
src/site/xdoc/manual/layouts.xml.vm | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
[11/15] logging-log4j2 git commit: LOG4J2-1342
MutableLogEvent.getMessage() returns this log event if message is not set
Posted by rp...@apache.org.
LOG4J2-1342 MutableLogEvent.getMessage() returns this log event if message is not set
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/f70deee8
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/f70deee8
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/f70deee8
Branch: refs/heads/master
Commit: f70deee8e93d4f0bdf641e495b6b5a0cd92c6dda
Parents: ba8d290
Author: rpopma <rp...@apache.org>
Authored: Fri Apr 22 14:38:49 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Apr 22 14:38:49 2016 +0900
----------------------------------------------------------------------
.../org/apache/logging/log4j/core/impl/MutableLogEventTest.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f70deee8/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/MutableLogEventTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/MutableLogEventTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/MutableLogEventTest.java
index 40e13e8..8f7b4ef 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/MutableLogEventTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/MutableLogEventTest.java
@@ -102,7 +102,7 @@ public class MutableLogEventTest {
assertNull("fqcn", mutable.getLoggerFqcn());
assertNull("logger", mutable.getLoggerName());
assertNull("marker", mutable.getMarker());
- assertEquals("msg", new SimpleMessage(Strings.EMPTY), mutable.getMessage());
+ assertEquals("msg", mutable, mutable.getMessage());
assertEquals("nanoTm", 0, mutable.getNanoTime());
assertEquals("tid", 0, mutable.getThreadId());
assertNull("tname", mutable.getThreadName());
@@ -155,7 +155,7 @@ public class MutableLogEventTest {
assertNull("fqcn", mutable.getLoggerFqcn());
assertNull("logger", mutable.getLoggerName());
assertNull("marker", mutable.getMarker());
- assertEquals("msg", new SimpleMessage(Strings.EMPTY), mutable.getMessage());
+ assertEquals("msg", mutable, mutable.getMessage());
assertNull("thrwn", mutable.getThrown());
assertNull("source", mutable.getSource());
[02/15] logging-log4j2 git commit: LOG4J2-1342 added methods to
ReusableMessage to enable passing parameters to async logger background
threads
Posted by rp...@apache.org.
LOG4J2-1342 added methods to ReusableMessage to enable passing parameters to async logger background threads
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/a5f6a8be
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/a5f6a8be
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/a5f6a8be
Branch: refs/heads/master
Commit: a5f6a8be04eb8b7306b1419f967591635b2a2455
Parents: 8b09f29
Author: rpopma <rp...@apache.org>
Authored: Fri Apr 22 12:10:34 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Apr 22 12:10:34 2016 +0900
----------------------------------------------------------------------
.../logging/log4j/message/ReusableMessage.java | 31 +++++++
.../log4j/message/ReusableObjectMessage.java | 19 ++++
.../message/ReusableParameterizedMessage.java | 20 ++++
.../log4j/message/ReusableSimpleMessage.java | 18 ++++
.../core/async/AsyncLoggerConfigDisruptor.java | 2 +-
.../log4j/core/async/RingBufferLogEvent.java | 98 +++++++++++++-------
.../log4j/core/impl/MutableLogEvent.java | 67 ++++++++++---
7 files changed, 209 insertions(+), 46 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a5f6a8be/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableMessage.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableMessage.java b/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableMessage.java
index a6da9c4..0536b23 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableMessage.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableMessage.java
@@ -30,4 +30,35 @@ import org.apache.logging.log4j.util.StringBuilderFormattable;
*/
@PerformanceSensitive("allocation")
public interface ReusableMessage extends Message, StringBuilderFormattable {
+
+ /**
+ * Returns the parameter array that was used to initialize this reusable message and replaces it with the specified
+ * array. The returned parameter array will no longer be modified by this reusable message. The specified array is
+ * now "owned" by this reusable message and can be modified if necessary for the next log event.
+ * </p><p>
+ * ReusableMessages that have no parameters return the specified array.
+ * </p><p>
+ * This method is used by asynchronous loggers to pass the parameter array to a background thread without
+ * allocating new objects.
+ * The actual number of parameters in the returned array can be determined with {@link #getParameterCount()}.
+ * </p>
+ *
+ * @param emptyReplacement the parameter array that can be used for subsequent uses of this reusable message.
+ * This replacement array must have at least 10 elements (the number of varargs supported by the Logger
+ * API).
+ * @return the parameter array for the current message content. This may be a vararg array of any length, or it may
+ * be a reusable array of 10 elements used to hold the unrolled vararg parameters.
+ * @see #getParameterCount()
+ */
+ Object[] swapParameters(Object[] emptyReplacement);
+
+ /**
+ * Returns the number of parameters that was used to initialize this reusable message for the current content.
+ * <p>
+ * The parameter array returned by {@link #swapParameters(Object[])} may be larger than the actual number of
+ * parameters. Callers should use this method to determine how many elements the array contains.
+ * </p>
+ * @return the current number of parameters
+ */
+ short getParameterCount();
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a5f6a8be/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableObjectMessage.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableObjectMessage.java b/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableObjectMessage.java
index 12f62f4..920eff4 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableObjectMessage.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableObjectMessage.java
@@ -91,4 +91,23 @@ public class ReusableObjectMessage implements ReusableMessage {
public Throwable getThrowable() {
return obj instanceof Throwable ? (Throwable) obj : null;
}
+
+ /**
+ * This message does not have any parameters, so this method returns the specified array.
+ * @param emptyReplacement the parameter array to return
+ * @return the specified array
+ */
+ @Override
+ public Object[] swapParameters(final Object[] emptyReplacement) {
+ return emptyReplacement;
+ }
+
+ /**
+ * This message does not have any parameters so this method always returns zero.
+ * @return 0 (zero)
+ */
+ @Override
+ public short getParameterCount() {
+ return 0;
+ }
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a5f6a8be/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableParameterizedMessage.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableParameterizedMessage.java b/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableParameterizedMessage.java
index 87cdc1d..4913c64 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableParameterizedMessage.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableParameterizedMessage.java
@@ -55,6 +55,26 @@ public class ReusableParameterizedMessage implements ReusableMessage {
return varargs == null ? params : varargs;
}
+ // see interface javadoc
+ @Override
+ public Object[] swapParameters(final Object[] emptyReplacement) {
+ Object[] result;
+ if (varargs == null) {
+ result = params;
+ params = emptyReplacement;
+ } else {
+ result = varargs;
+ varargs = emptyReplacement;
+ }
+ return result;
+ }
+
+ // see interface javadoc
+ @Override
+ public short getParameterCount() {
+ return (short) argCount;
+ }
+
private void init(final String messagePattern, final int argCount, final Object[] paramArray) {
this.varargs = null;
this.messagePattern = messagePattern;
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a5f6a8be/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableSimpleMessage.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableSimpleMessage.java b/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableSimpleMessage.java
index ed6e39e..9fae16c 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableSimpleMessage.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableSimpleMessage.java
@@ -61,6 +61,24 @@ public class ReusableSimpleMessage implements ReusableMessage, CharSequence {
buffer.append(charSequence);
}
+ /**
+ * This message does not have any parameters, so this method returns the specified array.
+ * @param emptyReplacement the parameter array to return
+ * @return the specified array
+ */
+ @Override
+ public Object[] swapParameters(final Object[] emptyReplacement) {
+ return emptyReplacement;
+ }
+
+ /**
+ * This message does not have any parameters so this method always returns zero.
+ * @return 0 (zero)
+ */
+ @Override
+ public short getParameterCount() {
+ return 0;
+ }
// CharSequence impl
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a5f6a8be/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java
index 2c1b84f..503e7d8 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java
@@ -145,7 +145,7 @@ public class AsyncLoggerConfigDisruptor implements AsyncLoggerConfigDelegate {
private static final EventFactory<Log4jEventWrapper> MUTABLE_FACTORY = new EventFactory<Log4jEventWrapper>() {
@Override
public Log4jEventWrapper newInstance() {
- return new Log4jEventWrapper(new MutableLogEvent());
+ return new Log4jEventWrapper(new MutableLogEvent(new Object[10]));
}
};
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a5f6a8be/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
index e1e6ab0..72ae8ac 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
@@ -16,7 +16,11 @@
*/
package org.apache.logging.log4j.core.async;
-import com.lmax.disruptor.EventFactory;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.ThreadContext.ContextStack;
@@ -32,9 +36,7 @@ import org.apache.logging.log4j.message.SimpleMessage;
import org.apache.logging.log4j.message.TimestampMessage;
import org.apache.logging.log4j.util.Strings;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
+import com.lmax.disruptor.EventFactory;
/**
* When the Disruptor is started, the RingBuffer is populated with event objects. These objects are then re-used during
@@ -46,7 +48,6 @@ public class RingBufferLogEvent implements LogEvent, ReusableMessage, CharSequen
public static final Factory FACTORY = new Factory();
private static final long serialVersionUID = 8462119088943934758L;
- private static final Object[] PARAMS = new Object[0];
private static final Message EMPTY = new SimpleMessage(Strings.EMPTY);
/**
@@ -59,56 +60,63 @@ public class RingBufferLogEvent implements LogEvent, ReusableMessage, CharSequen
RingBufferLogEvent result = new RingBufferLogEvent();
if (Constants.ENABLE_THREADLOCALS) {
result.messageText = new StringBuilder(Constants.INITIAL_REUSABLE_MESSAGE_SIZE);
+ result.parameters = new Object[10];
}
return result;
}
}
- private transient AsyncLogger asyncLogger;
- private String loggerName;
- private Marker marker;
- private String fqcn;
+ private int threadPriority;
+ private long threadId;
+ private long currentTimeMillis;
+ private long nanoTime;
+ private short parameterCount;
+ private boolean includeLocation;
+ private boolean endOfBatch = false;
private Level level;
- private StringBuilder messageText;
+ private String threadName;
+ private String loggerName;
private Message message;
+ private StringBuilder messageText;
+ private Object[] parameters;
private transient Throwable thrown;
private ThrowableProxy thrownProxy;
private Map<String, String> contextMap;
- private ContextStack contextStack;
- private long threadId;
- private String threadName;
- private int threadPriority;
+ private Marker marker;
+ private String fqcn;
private StackTraceElement location;
- private long currentTimeMillis;
- private boolean endOfBatch;
- private boolean includeLocation;
- private long nanoTime;
+ private ContextStack contextStack;
+
+ private transient AsyncLogger asyncLogger;
public void setValues(final AsyncLogger anAsyncLogger, final String aLoggerName, final Marker aMarker,
final String theFqcn, final Level aLevel, final Message msg, final Throwable aThrowable,
final Map<String, String> aMap, final ContextStack aContextStack, long threadId,
final String threadName, int threadPriority, final StackTraceElement aLocation, final long aCurrentTimeMillis, final long aNanoTime) {
- this.asyncLogger = anAsyncLogger;
- this.loggerName = aLoggerName;
- this.marker = aMarker;
- this.fqcn = theFqcn;
+ this.threadPriority = threadPriority;
+ this.threadId = threadId;
+ this.currentTimeMillis = aCurrentTimeMillis;
+ this.nanoTime = aNanoTime;
this.level = aLevel;
+ this.threadName = threadName;
+ this.loggerName = aLoggerName;
+ setMessage(msg);
this.thrown = aThrowable;
this.thrownProxy = null;
this.contextMap = aMap;
- this.contextStack = aContextStack;
- this.threadId = threadId;
- this.threadName = threadName;
- this.threadPriority = threadPriority;
+ this.marker = aMarker;
+ this.fqcn = theFqcn;
this.location = aLocation;
- this.currentTimeMillis = aCurrentTimeMillis;
- this.nanoTime = aNanoTime;
- setMessage(msg);
+ this.contextStack = aContextStack;
+ this.asyncLogger = anAsyncLogger;
}
private void setMessage(final Message msg) {
if (msg instanceof ReusableMessage) {
- ((ReusableMessage) msg).formatTo(getMessageTextForWriting());
+ ReusableMessage reusable = (ReusableMessage) msg;
+ reusable.formatTo(getMessageTextForWriting());
+ parameters = reusable.swapParameters(parameters);
+ parameterCount = reusable.getParameterCount();
} else {
// if the Message instance is reused, there is no point in freezing its message here
if (!Constants.FORMAT_MESSAGES_IN_BACKGROUND && msg != null) { // LOG4J2-898: user may choose
@@ -215,7 +223,7 @@ public class RingBufferLogEvent implements LogEvent, ReusableMessage, CharSequen
*/
@Override
public Object[] getParameters() {
- return PARAMS;
+ return parameters == null ? null : Arrays.copyOf(parameters, parameterCount);
}
/**
@@ -234,6 +242,27 @@ public class RingBufferLogEvent implements LogEvent, ReusableMessage, CharSequen
buffer.append(messageText);
}
+ /**
+ * Replaces this ReusableMessage's parameter array with the specified value and return the original array
+ * @param emptyReplacement the parameter array that can be used for subsequent uses of this reusable message
+ * @return the original parameter array
+ * @see ReusableMessage#swapParameters(Object[])
+ */
+ @Override
+ public Object[] swapParameters(final Object[] emptyReplacement) {
+ final Object[] result = this.parameters;
+ this.parameters = emptyReplacement;
+ return result;
+ }
+
+ /*
+ * @see ReusableMessage#getParameterCount
+ */
+ @Override
+ public short getParameterCount() {
+ return parameterCount;
+ }
+
// CharSequence impl
@@ -362,7 +391,14 @@ public class RingBufferLogEvent implements LogEvent, ReusableMessage, CharSequen
this.contextMap = null;
this.contextStack = null;
this.location = null;
+
trimMessageText();
+
+ if (parameters != null) {
+ for (int i = 0; i < parameters.length; i++) {
+ parameters[i] = null;
+ }
+ }
}
// ensure that excessively long char[] arrays are not kept in memory forever
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a5f6a8be/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 b619615..0393b0c 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
@@ -18,6 +18,7 @@ package org.apache.logging.log4j.core.impl;
import java.io.InvalidObjectException;
import java.io.ObjectInputStream;
+import java.util.Arrays;
import java.util.Map;
import org.apache.logging.log4j.Level;
@@ -35,27 +36,36 @@ import org.apache.logging.log4j.util.Strings;
* @since 2.6
*/
public class MutableLogEvent implements LogEvent, ReusableMessage {
- private static final Object[] PARAMS = new Object[0];
private static final Message EMPTY = new SimpleMessage(Strings.EMPTY);
- private String loggerFqcn;
- private Marker marker;
+ private int threadPriority;
+ private long threadId;
+ private long timeMillis;
+ private long nanoTime;
+ private short parameterCount;
+ private boolean includeLocation;
+ private boolean endOfBatch = false;
private Level level;
+ private String threadName;
private String loggerName;
private Message message;
- private long timeMillis;
+ private StringBuilder messageText;
+ private Object[] parameters;
private Throwable thrown;
private ThrowableProxy thrownProxy;
private Map<String, String> contextMap;
- private ThreadContext.ContextStack contextStack;
- private long threadId;
- private String threadName;
- private int threadPriority;
+ private Marker marker;
+ private String loggerFqcn;
private StackTraceElement source;
- private boolean includeLocation;
- private boolean endOfBatch = false;
- private long nanoTime;
- private StringBuilder messageText;
+ private ThreadContext.ContextStack contextStack;
+
+ public MutableLogEvent() {
+ this(null);
+ }
+
+ public MutableLogEvent(final Object[] replacementParameters) {
+ this.parameters = replacementParameters;
+ }
/**
* Initialize the fields of this {@code MutableLogEvent} from another event.
@@ -107,6 +117,11 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
// threadName = null; // no need to clear threadName
trimMessageText();
+ if (parameters != null) {
+ for (int i = 0; i < parameters.length; i++) {
+ parameters[i] = null;
+ }
+ }
// primitive fields that cannot be cleared:
//timeMillis;
@@ -171,7 +186,10 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
public void setMessage(final Message msg) {
if (msg instanceof ReusableMessage) {
- ((ReusableMessage) msg).formatTo(getMessageTextForWriting()); // init messageText
+ ReusableMessage reusable = (ReusableMessage) msg;
+ reusable.formatTo(getMessageTextForWriting());
+ parameters = reusable.swapParameters(parameters);
+ parameterCount = reusable.getParameterCount();
} else {
// if the Message instance is reused, there is no point in freezing its message here
if (!Constants.FORMAT_MESSAGES_IN_BACKGROUND && msg != null) { // LOG4J2-898: user may choose
@@ -212,7 +230,7 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
*/
@Override
public Object[] getParameters() {
- return PARAMS;
+ return parameters == null ? null : Arrays.copyOf(parameters, parameterCount);
}
/**
@@ -231,6 +249,27 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
buffer.append(messageText);
}
+ /**
+ * Replaces this ReusableMessage's parameter array with the specified value and return the original array
+ * @param emptyReplacement the parameter array that can be used for subsequent uses of this reusable message
+ * @return the original parameter array
+ * @see ReusableMessage#swapParameters(Object[])
+ */
+ @Override
+ public Object[] swapParameters(final Object[] emptyReplacement) {
+ final Object[] result = this.parameters;
+ this.parameters = emptyReplacement;
+ return result;
+ }
+
+ /*
+ * @see ReusableMessage#getParameterCount
+ */
+ @Override
+ public short getParameterCount() {
+ return parameterCount;
+ }
+
@Override
public Throwable getThrown() {
return thrown;
[07/15] logging-log4j2 git commit: LOG4J2-1342 added method
ReusableMessage#memento() to take snapshot (used by AsyncAppender)
Posted by rp...@apache.org.
LOG4J2-1342 added method ReusableMessage#memento() to take snapshot (used by AsyncAppender)
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/2d24c651
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/2d24c651
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/2d24c651
Branch: refs/heads/master
Commit: 2d24c65138ca3608b78f69a4df4cb174e983811c
Parents: 73f12f4
Author: rpopma <rp...@apache.org>
Authored: Fri Apr 22 14:36:21 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Apr 22 14:36:21 2016 +0900
----------------------------------------------------------------------
.../org/apache/logging/log4j/message/ReusableMessage.java | 8 ++++++++
1 file changed, 8 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2d24c651/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableMessage.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableMessage.java b/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableMessage.java
index 0536b23..82e40ac 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableMessage.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableMessage.java
@@ -61,4 +61,12 @@ public interface ReusableMessage extends Message, StringBuilderFormattable {
* @return the current number of parameters
*/
short getParameterCount();
+
+ /**
+ * Returns an immutable snapshot of the current internal state of this reusable message. The returned snapshot
+ * will not be affected by subsequent modifications of this reusable message.
+ *
+ * @return an immutable snapshot of this message
+ */
+ Message memento();
}
[13/15] logging-log4j2 git commit: LOG4J2-1334 synchronous logging is
now garbage-free; enable this by default
Posted by rp...@apache.org.
LOG4J2-1334 synchronous logging is now garbage-free; enable this by default
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/c0459ff3
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/c0459ff3
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/c0459ff3
Branch: refs/heads/master
Commit: c0459ff304a7725d74577a658d3cdbd81cf72d3a
Parents: d9e84d1
Author: rpopma <rp...@apache.org>
Authored: Fri Apr 22 14:54:09 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Apr 22 14:54:09 2016 +0900
----------------------------------------------------------------------
.../java/org/apache/logging/log4j/core/config/LoggerConfig.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c0459ff3/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
index 7b030c6..3a3e04c 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
@@ -84,7 +84,7 @@ public class LoggerConfig extends AbstractFilterable {
}
}
if (LOG_EVENT_FACTORY == null) {
- LOG_EVENT_FACTORY = false //Constants.ENABLE_THREADLOCALS
+ LOG_EVENT_FACTORY = Constants.ENABLE_THREADLOCALS
? new ReusableLogEventFactory()
: new DefaultLogEventFactory();
}
[03/15] logging-log4j2 git commit: LOG4J2-1342 bugfix: don't set
ReusableParameterizedMessage array to null
Posted by rp...@apache.org.
LOG4J2-1342 bugfix: don't set ReusableParameterizedMessage array to 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/1eadde59
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/1eadde59
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/1eadde59
Branch: refs/heads/master
Commit: 1eadde5971f209283275c59138867d9b55568ea4
Parents: a5f6a8b
Author: rpopma <rp...@apache.org>
Authored: Fri Apr 22 12:50:28 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Apr 22 12:50:28 2016 +0900
----------------------------------------------------------------------
.../apache/logging/log4j/core/async/RingBufferLogEvent.java | 6 ++++--
.../org/apache/logging/log4j/core/impl/MutableLogEvent.java | 6 ++++--
2 files changed, 8 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1eadde59/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
index 72ae8ac..ab5e3d0 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
@@ -115,8 +115,10 @@ public class RingBufferLogEvent implements LogEvent, ReusableMessage, CharSequen
if (msg instanceof ReusableMessage) {
ReusableMessage reusable = (ReusableMessage) msg;
reusable.formatTo(getMessageTextForWriting());
- parameters = reusable.swapParameters(parameters);
- parameterCount = reusable.getParameterCount();
+ if (parameters != null) {
+ parameters = reusable.swapParameters(parameters);
+ parameterCount = reusable.getParameterCount();
+ }
} else {
// if the Message instance is reused, there is no point in freezing its message here
if (!Constants.FORMAT_MESSAGES_IN_BACKGROUND && msg != null) { // LOG4J2-898: user may choose
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1eadde59/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 0393b0c..e256723 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
@@ -188,8 +188,10 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
if (msg instanceof ReusableMessage) {
ReusableMessage reusable = (ReusableMessage) msg;
reusable.formatTo(getMessageTextForWriting());
- parameters = reusable.swapParameters(parameters);
- parameterCount = reusable.getParameterCount();
+ if (parameters != null) {
+ parameters = reusable.swapParameters(parameters);
+ parameterCount = reusable.getParameterCount();
+ }
} else {
// if the Message instance is reused, there is no point in freezing its message here
if (!Constants.FORMAT_MESSAGES_IN_BACKGROUND && msg != null) { // LOG4J2-898: user may choose
[05/15] logging-log4j2 git commit: LOG4J2-1342 use more reliable
CountDownLatch to ensure background thread is finished
Posted by rp...@apache.org.
LOG4J2-1342 use more reliable CountDownLatch to ensure background thread is finished
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/2cfc07bd
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/2cfc07bd
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/2cfc07bd
Branch: refs/heads/master
Commit: 2cfc07bdb0222aae9f501ebfb405e8d8ecd33d5a
Parents: aab635f
Author: rpopma <rp...@apache.org>
Authored: Fri Apr 22 14:24:00 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Apr 22 14:24:00 2016 +0900
----------------------------------------------------------------------
.../logging/log4j/core/layout/CsvParameterLayoutTest.java | 9 +++++----
.../apache/logging/log4j/test/appender/ListAppender.java | 6 ++++++
2 files changed, 11 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2cfc07bd/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/CsvParameterLayoutTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/CsvParameterLayoutTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/CsvParameterLayoutTest.java
index ce3abfc..a51db99 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/CsvParameterLayoutTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/CsvParameterLayoutTest.java
@@ -21,6 +21,8 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
import org.apache.commons.csv.CSVFormat;
import org.apache.logging.log4j.Level;
@@ -97,6 +99,8 @@ public class CsvParameterLayoutTest {
final ListAppender appender = new ListAppender("List", null, layout, true, false);
appender.start();
+ appender.countDownLatch = new CountDownLatch(4);
+
// set appender on root and set level to debug
root.addAppender(appender);
root.setLevel(Level.DEBUG);
@@ -109,10 +113,7 @@ public class CsvParameterLayoutTest {
}
// wait until background thread finished processing
- int maxTries = 50;
- while (appender.getMessages().size() < 4 && maxTries-- > 0) {
- Thread.sleep(1L);
- }
+ appender.countDownLatch.await(10, TimeUnit.SECONDS);
assertEquals("Background thread did not finish processing: msg count", 4, appender.getMessages().size());
// don't stop appender until background thread is done
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2cfc07bd/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 19aeaee..acab7c1 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
@@ -20,6 +20,7 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.concurrent.CountDownLatch;
import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.Layout;
@@ -60,6 +61,8 @@ public class ListAppender extends AbstractAppender {
private static final String WINDOWS_LINE_SEP = "\r\n";
+ public CountDownLatch countDownLatch = null;
+
public ListAppender(final String name) {
super(name, null, null);
newLine = false;
@@ -99,6 +102,9 @@ public class ListAppender extends AbstractAppender {
} else {
write(layout.toByteArray(event));
}
+ if (countDownLatch != null) {
+ countDownLatch.countDown();
+ }
}
void write(final byte[] bytes) {
[06/15] logging-log4j2 git commit: LOG4J2-1334 don't take snapshot of
message, delegate to MutableLogEvent
Posted by rp...@apache.org.
LOG4J2-1334 don't take snapshot of message, delegate to MutableLogEvent
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/73f12f4f
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/73f12f4f
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/73f12f4f
Branch: refs/heads/master
Commit: 73f12f4f7829c717bbc79b1eb128aac72e52ce09
Parents: 2cfc07b
Author: rpopma <rp...@apache.org>
Authored: Fri Apr 22 14:33:28 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Apr 22 14:33:28 2016 +0900
----------------------------------------------------------------------
.../logging/log4j/core/async/AsyncLoggerConfigDisruptor.java | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/73f12f4f/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java
index 503e7d8..60494e0 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java
@@ -145,7 +145,7 @@ public class AsyncLoggerConfigDisruptor implements AsyncLoggerConfigDelegate {
private static final EventFactory<Log4jEventWrapper> MUTABLE_FACTORY = new EventFactory<Log4jEventWrapper>() {
@Override
public Log4jEventWrapper newInstance() {
- return new Log4jEventWrapper(new MutableLogEvent(new Object[10]));
+ return new Log4jEventWrapper(new MutableLogEvent());
}
};
@@ -324,8 +324,6 @@ public class AsyncLoggerConfigDisruptor implements AsyncLoggerConfigDelegate {
final LogEvent logEvent = ensureImmutable(event);
if (logEvent instanceof Log4jLogEvent && logEvent.getMessage() instanceof ReusableMessage) {
((Log4jLogEvent) logEvent).makeMessageImmutable();
- } else if (!Constants.FORMAT_MESSAGES_IN_BACKGROUND) { // LOG4J2-898: user may choose
- logEvent.getMessage().getFormattedMessage(); // LOG4J2-763: ask message to freeze parameters
}
return logEvent;
}
[09/15] logging-log4j2 git commit: LOG4J2-1342 added implementation
of new method #memento()
Posted by rp...@apache.org.
LOG4J2-1342 added implementation of new method #memento()
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/f34a555c
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/f34a555c
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/f34a555c
Branch: refs/heads/master
Commit: f34a555cd402337af286335b492f2427cfbaff29
Parents: 1c2f168
Author: rpopma <rp...@apache.org>
Authored: Fri Apr 22 14:37:26 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Apr 22 14:37:26 2016 +0900
----------------------------------------------------------------------
.../apache/logging/log4j/core/async/RingBufferLogEvent.java | 9 +++++++++
1 file changed, 9 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f34a555c/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
index ab5e3d0..f687ff4 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
@@ -31,6 +31,7 @@ import org.apache.logging.log4j.core.impl.ThrowableProxy;
import org.apache.logging.log4j.core.lookup.StrSubstitutor;
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.message.TimestampMessage;
@@ -265,6 +266,14 @@ public class RingBufferLogEvent implements LogEvent, ReusableMessage, CharSequen
return parameterCount;
}
+ @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);
+ }
// CharSequence impl
[08/15] logging-log4j2 git commit: LOG4J2-1342 added implementation
of new method #memento()
Posted by rp...@apache.org.
LOG4J2-1342 added implementation of new method #memento()
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/1c2f1685
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/1c2f1685
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/1c2f1685
Branch: refs/heads/master
Commit: 1c2f168515794e1c9ebaf53d5561ca74fb369a05
Parents: 2d24c65
Author: rpopma <rp...@apache.org>
Authored: Fri Apr 22 14:37:07 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Apr 22 14:37:07 2016 +0900
----------------------------------------------------------------------
.../org/apache/logging/log4j/message/ReusableObjectMessage.java | 5 +++++
.../logging/log4j/message/ReusableParameterizedMessage.java | 5 +++++
.../org/apache/logging/log4j/message/ReusableSimpleMessage.java | 5 +++++
3 files changed, 15 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1c2f1685/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableObjectMessage.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableObjectMessage.java b/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableObjectMessage.java
index 920eff4..fddc0eb 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableObjectMessage.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableObjectMessage.java
@@ -110,4 +110,9 @@ public class ReusableObjectMessage implements ReusableMessage {
public short getParameterCount() {
return 0;
}
+
+ @Override
+ public Message memento() {
+ return new ObjectMessage(obj);
+ }
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1c2f1685/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableParameterizedMessage.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableParameterizedMessage.java b/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableParameterizedMessage.java
index 12f4346..24c0e7d 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableParameterizedMessage.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableParameterizedMessage.java
@@ -76,6 +76,11 @@ public class ReusableParameterizedMessage implements ReusableMessage {
return (short) argCount;
}
+ @Override
+ public Message memento() {
+ return new ParameterizedMessage(messagePattern, getTrimmedParams());
+ }
+
private void init(final String messagePattern, final int argCount, final Object[] paramArray) {
this.varargs = null;
this.messagePattern = messagePattern;
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1c2f1685/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableSimpleMessage.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableSimpleMessage.java b/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableSimpleMessage.java
index 9fae16c..d894ef7 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableSimpleMessage.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableSimpleMessage.java
@@ -80,6 +80,11 @@ public class ReusableSimpleMessage implements ReusableMessage, CharSequence {
return 0;
}
+ @Override
+ public Message memento() {
+ return new SimpleMessage(charSequence);
+ }
+
// CharSequence impl
@Override
[12/15] logging-log4j2 git commit: LOG4J2-1342 use new method
ReusableMessage#memento() to take snapshot without losing parameter
information
Posted by rp...@apache.org.
LOG4J2-1342 use new method ReusableMessage#memento() to take snapshot without losing parameter information
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/d9e84d1b
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/d9e84d1b
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/d9e84d1b
Branch: refs/heads/master
Commit: d9e84d1b18fdd8ebdcc85b23b2c319cdf62f1670
Parents: f70deee
Author: rpopma <rp...@apache.org>
Authored: Fri Apr 22 14:39:34 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Apr 22 14:39:34 2016 +0900
----------------------------------------------------------------------
.../java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d9e84d1b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
index 26b35d3..776fba7 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
@@ -844,7 +844,7 @@ public Log4jLogEvent(final String loggerName, final Marker marker, final String
}
private Message memento(final ReusableMessage message) {
- return new SimpleMessage(message.getFormattedMessage());
+ return message.memento();
}
/**
[04/15] logging-log4j2 git commit: LOG4J2-1342 ensure internal array
is not set to null by incorrect swap() invocation
Posted by rp...@apache.org.
LOG4J2-1342 ensure internal array is not set to null by incorrect swap() invocation
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/aab635fd
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/aab635fd
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/aab635fd
Branch: refs/heads/master
Commit: aab635fd698c2078b9ad7d5917b4264640054047
Parents: 1eadde5
Author: rpopma <rp...@apache.org>
Authored: Fri Apr 22 12:51:13 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Apr 22 12:51:13 2016 +0900
----------------------------------------------------------------------
.../logging/log4j/message/ReusableParameterizedMessage.java | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/aab635fd/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableParameterizedMessage.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableParameterizedMessage.java b/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableParameterizedMessage.java
index 4913c64..12f4346 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableParameterizedMessage.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableParameterizedMessage.java
@@ -17,6 +17,7 @@
package org.apache.logging.log4j.message;
import java.util.Arrays;
+import java.util.Objects;
import org.apache.logging.log4j.util.PerformanceSensitive;
@@ -61,10 +62,10 @@ public class ReusableParameterizedMessage implements ReusableMessage {
Object[] result;
if (varargs == null) {
result = params;
- params = emptyReplacement;
+ params = Objects.requireNonNull(emptyReplacement);
} else {
result = varargs;
- varargs = emptyReplacement;
+ varargs = Objects.requireNonNull(emptyReplacement);
}
return result;
}