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/01/12 17:50:09 UTC
[01/50] logging-log4j2 git commit: LOG4J2-1080 added unit tests
Repository: logging-log4j2
Updated Branches:
refs/heads/LOG4J-1181 e28d50be0 -> 6e858b02f
LOG4J2-1080 added unit tests
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/d97cd829
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/d97cd829
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/d97cd829
Branch: refs/heads/LOG4J-1181
Commit: d97cd829bd99d62440eee2649fa3b329683be81f
Parents: 3cc036c
Author: rpopma <rp...@apache.org>
Authored: Wed Dec 23 22:14:33 2015 +0900
Committer: rpopma <rp...@apache.org>
Committed: Wed Dec 23 22:14:33 2015 +0900
----------------------------------------------------------------------
.../core/async/AsyncEventRouterFactoryTest.java | 153 +++++++++++++++++++
.../core/async/DefaultAsyncEventRouterTest.java | 67 ++++++++
.../async/DiscardingAsyncEventRouterTest.java | 146 ++++++++++++++++++
3 files changed, 366 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d97cd829/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncEventRouterFactoryTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncEventRouterFactoryTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncEventRouterFactoryTest.java
new file mode 100644
index 0000000..804401b
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncEventRouterFactoryTest.java
@@ -0,0 +1,153 @@
+/*
+ * 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.async;
+
+import org.apache.logging.log4j.Level;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests the AsyncEventRouterFactory class.
+ */
+public class AsyncEventRouterFactoryTest {
+
+ @After
+ public void after() {
+ clearProperties();
+ }
+
+ @Before
+ public void before() {
+ clearProperties();
+ }
+
+ private void clearProperties() {
+ System.clearProperty(AsyncEventRouterFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER);
+ System.clearProperty(AsyncEventRouterFactory.PROPERTY_NAME_DISCARDING_QUEUE_RATIO);
+ System.clearProperty(AsyncEventRouterFactory.PROPERTY_NAME_DISCARDING_THRESHOLD_LEVEL);
+ }
+
+ @Test
+ public void testCreateReturnsDefaultRouterByDefault() throws Exception {
+ AsyncEventRouter router = AsyncEventRouterFactory.create(256);
+ assertEquals(DefaultAsyncEventRouter.class, router.getClass());
+ }
+
+ @Test
+ public void testCreateReturnsDiscardingRouterIfSpecified() throws Exception {
+ System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER,
+ AsyncEventRouterFactory.PROPERTY_VALUE_DISCARDING_ASYNC_EVENT_ROUTER);
+ assertEquals(DiscardingAsyncEventRouter.class, AsyncEventRouterFactory.create(256).getClass());
+
+ System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER,
+ DiscardingAsyncEventRouter.class.getSimpleName());
+ assertEquals(DiscardingAsyncEventRouter.class, AsyncEventRouterFactory.create(256).getClass());
+
+ System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER,
+ DiscardingAsyncEventRouter.class.getName());
+ assertEquals(DiscardingAsyncEventRouter.class, AsyncEventRouterFactory.create(256).getClass());
+ }
+
+ @Test
+ public void testCreateDiscardingRouterDefaultThresholdLevelInfo() throws Exception {
+ System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER,
+ AsyncEventRouterFactory.PROPERTY_VALUE_DISCARDING_ASYNC_EVENT_ROUTER);
+ assertEquals(Level.INFO, ((DiscardingAsyncEventRouter) AsyncEventRouterFactory.create(256)).
+ getThresholdLevel());
+ }
+
+ @Test
+ public void testCreateDiscardingRouterDefaultThresholdQueueRemainingCapacity() throws Exception {
+ System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER,
+ AsyncEventRouterFactory.PROPERTY_VALUE_DISCARDING_ASYNC_EVENT_ROUTER);
+ assertEquals((int) (256 * (1.0 - 0.8)), ((DiscardingAsyncEventRouter) AsyncEventRouterFactory.create(256)).
+ getThresholdQueueRemainingCapacity());
+ }
+
+ @Test
+ public void testCreateDiscardingRouterThresholdLevelCustomizable() throws Exception {
+ System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER,
+ AsyncEventRouterFactory.PROPERTY_VALUE_DISCARDING_ASYNC_EVENT_ROUTER);
+
+ for (Level level : Level.values()) {
+ System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_DISCARDING_THRESHOLD_LEVEL,
+ level.name());
+ assertEquals(level, ((DiscardingAsyncEventRouter) AsyncEventRouterFactory.create(256)).
+ getThresholdLevel());
+ }
+ }
+
+ @Test
+ public void testCreateDiscardingRouterThresholdQueueCapacityCustomizable() throws Exception {
+ System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER,
+ AsyncEventRouterFactory.PROPERTY_VALUE_DISCARDING_ASYNC_EVENT_ROUTER);
+ float[] ratios = new float[] {0.1f, 0.2f, 0.5f, 0.8f, 0.9f};
+ for (final float ratio : ratios) {
+ System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_DISCARDING_QUEUE_RATIO,
+ String.valueOf(ratio));
+ int expected = (int) (256 * (1.0 - ratio));
+ assertEquals(expected, ((DiscardingAsyncEventRouter) AsyncEventRouterFactory.create(256)).
+ getThresholdQueueRemainingCapacity());
+ }
+ }
+
+ static class CustomRouterDefaultConstructor implements AsyncEventRouter {
+ public CustomRouterDefaultConstructor() {
+ }
+
+ @Override
+ public EventRoute getRoute(final long backgroundThreadId, final Level level, final int queueSize,
+ final int queueRemainingCapacity) {
+ return null;
+ }
+ }
+
+ static class CustomRouterIntConstructor implements AsyncEventRouter {
+ public CustomRouterIntConstructor(int queueSize) {
+ }
+
+ @Override
+ public EventRoute getRoute(final long backgroundThreadId, final Level level, final int queueSize,
+ final int queueRemainingCapacity) {
+ return null;
+ }
+ }
+
+ static class DoesNotImplementInterface {
+ }
+
+ @Test
+ public void testCreateReturnsCustomRouterIfSpecified() throws Exception {
+ System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER,
+ CustomRouterDefaultConstructor.class.getName());
+ assertEquals(CustomRouterDefaultConstructor.class, AsyncEventRouterFactory.create(256).getClass());
+
+ System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER,
+ CustomRouterIntConstructor.class.getName());
+ assertEquals(CustomRouterIntConstructor.class, AsyncEventRouterFactory.create(256).getClass());
+ }
+
+ @Test
+ public void testCreateReturnsDefaultRouterIfSpecifiedCustomRouterFails() throws Exception {
+ System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER,
+ DoesNotImplementInterface.class.getName());
+ assertEquals(DefaultAsyncEventRouter.class, AsyncEventRouterFactory.create(256).getClass());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d97cd829/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DefaultAsyncEventRouterTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DefaultAsyncEventRouterTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DefaultAsyncEventRouterTest.java
new file mode 100644
index 0000000..dcec225
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DefaultAsyncEventRouterTest.java
@@ -0,0 +1,67 @@
+/*
+ * 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.async;
+
+import org.apache.logging.log4j.Level;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests the DefaultAsyncEventRouter class.
+ */
+public class DefaultAsyncEventRouterTest {
+
+ private static long currentThreadId() {
+ return Thread.currentThread().getId();
+ }
+
+ private static long otherThreadId() {
+ return -1;
+ }
+
+ @Test
+ public void testGetRouteEnqueuesIfQueueNotFull() throws Exception {
+ DefaultAsyncEventRouter router = new DefaultAsyncEventRouter();
+ assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.OFF, 256, 256));
+ assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.OFF, 256, 256));
+ assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.ALL, 256, 256));
+ assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.ALL, 256, 256));
+ assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.ALL, 256, 255));
+ assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.ALL, 256, 255));
+ assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.OFF, 256, 255));
+ assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.OFF, 256, 255));
+ assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.ALL, 256, 1));
+ assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.ALL, 256, 1));
+ assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.OFF, 256, 1));
+ assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.OFF, 256, 1));
+ }
+
+ @Test
+ public void testGetRouteEnqueuesIfQueueFullAndCalledFromDifferentThread() throws Exception {
+ DefaultAsyncEventRouter router = new DefaultAsyncEventRouter();
+ assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.ALL, 512, 0));
+ assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.OFF, 512, 0));
+ }
+
+ @Test
+ public void testGetRouteSynchronousIfQueueFullAndCalledFromSameThread() throws Exception {
+ DefaultAsyncEventRouter router = new DefaultAsyncEventRouter();
+ assertEquals(EventRoute.SYNCHRONOUS, router.getRoute(currentThreadId(), Level.ALL, 512, 0));
+ assertEquals(EventRoute.SYNCHRONOUS, router.getRoute(currentThreadId(), Level.OFF, 512, 0));
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d97cd829/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DiscardingAsyncEventRouterTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DiscardingAsyncEventRouterTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DiscardingAsyncEventRouterTest.java
new file mode 100644
index 0000000..1e9b66a
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DiscardingAsyncEventRouterTest.java
@@ -0,0 +1,146 @@
+/*
+ * 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.async;
+
+import org.apache.logging.log4j.Level;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests the DiscardingAsyncEventRouter class..
+ */
+public class DiscardingAsyncEventRouterTest {
+
+ private static long currentThreadId() {
+ return Thread.currentThread().getId();
+ }
+
+ private static long otherThreadId() {
+ return -1;
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testConstructorDisallowsNullThresholdLevel() {
+ new DiscardingAsyncEventRouter(128, 0.5F, null);
+ }
+
+ @Test
+ public void testThresholdLevelIsConstructorValue() {
+ assertSame(Level.ALL, new DiscardingAsyncEventRouter(128, 0.5F, Level.ALL).getThresholdLevel());
+ assertSame(Level.OFF, new DiscardingAsyncEventRouter(128, 0.5F, Level.OFF).getThresholdLevel());
+ assertSame(Level.INFO, new DiscardingAsyncEventRouter(128, 0.5F, Level.INFO).getThresholdLevel());
+ }
+
+ @Test
+ public void testThresholdRemainingCapacityBasedOnConstructorValues() {
+ // discard when queue full
+ assertEquals(0, new DiscardingAsyncEventRouter(4, 1F, Level.ALL).getThresholdQueueRemainingCapacity());
+
+ // discard when queue half full
+ assertEquals(2, new DiscardingAsyncEventRouter(4, 0.5F, Level.ALL).getThresholdQueueRemainingCapacity());
+
+ // discard even if queue empty
+ assertEquals(4, new DiscardingAsyncEventRouter(4, 0F, Level.ALL).getThresholdQueueRemainingCapacity());
+ }
+
+ @Test
+ public void testGetRouteEnqueuesIfThresholdCapacityNotReached() throws Exception {
+ DiscardingAsyncEventRouter router = new DiscardingAsyncEventRouter(256, 0.5F, Level.WARN);
+ assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.OFF, 256, 256));
+ assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.OFF, 256, 256));
+ assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.ALL, 256, 256));
+ assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.ALL, 256, 256));
+ assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.ALL, 256, 255));
+ assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.ALL, 256, 255));
+ assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.OFF, 256, 255));
+ assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.OFF, 256, 255));
+ assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.FATAL, 256, 129));
+ assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.FATAL, 256, 129));
+ assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.TRACE, 256, 129));
+ assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.TRACE, 256, 129));
+ }
+
+ @Test
+ public void testGetRouteDiscardsIfThresholdCapacityReachedAndLevelEqualOrLessSpecificThanThreshold()
+ throws Exception {
+ DiscardingAsyncEventRouter router = new DiscardingAsyncEventRouter(256, 0.5F, Level.WARN);
+
+ for (Level level : new Level[] {Level.WARN, Level.INFO, Level.DEBUG, Level.TRACE, Level.ALL}) {
+ assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(currentThreadId(), level, 256, 1));
+ assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(otherThreadId(), level, 256, 1));
+ assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(currentThreadId(), level, 256, 128));
+ assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(otherThreadId(), level, 256, 128));
+ }
+ }
+
+ @Test
+ public void testGetRouteDiscardsIfQueueFullAndLevelEqualOrLessSpecificThanThreshold() throws Exception {
+ DiscardingAsyncEventRouter router = new DiscardingAsyncEventRouter(256, 0.5F, Level.WARN);
+
+ for (Level level : new Level[] {Level.WARN, Level.INFO, Level.DEBUG, Level.TRACE, Level.ALL}) {
+ assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(currentThreadId(), level, 256, 0));
+ assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(otherThreadId(), level, 256, 0));
+ }
+ }
+
+ @Test
+ public void testGetRouteEnqueuesIfThresholdCapacityReachedButLevelMoreSpecificThanThreshold()
+ throws Exception {
+ DiscardingAsyncEventRouter router = new DiscardingAsyncEventRouter(256, 0.5F, Level.WARN);
+
+ for (Level level : new Level[] {Level.ERROR, Level.FATAL, Level.OFF}) {
+ assertEquals(level.name(), EventRoute.ENQUEUE, router.getRoute(currentThreadId(), level, 256, 1));
+ assertEquals(level.name(), EventRoute.ENQUEUE, router.getRoute(otherThreadId(), level, 256, 1));
+ assertEquals(level.name(), EventRoute.ENQUEUE, router.getRoute(currentThreadId(), level, 256, 128));
+ assertEquals(level.name(), EventRoute.ENQUEUE, router.getRoute(otherThreadId(), level, 256, 128));
+ }
+ }
+
+ @Test
+ public void testGetRouteEnqueuesIfOtherThreadQueueFullAndLevelMoreSpecificThanThreshold() throws Exception {
+ DiscardingAsyncEventRouter router = new DiscardingAsyncEventRouter(256, 0.5F, Level.WARN);
+
+ for (Level level : new Level[] {Level.ERROR, Level.FATAL, Level.OFF}) {
+ assertEquals(level.name(), EventRoute.ENQUEUE, router.getRoute(otherThreadId(), level, 256, 0));
+ }
+ }
+
+ @Test
+ public void testGetRouteSynchronousIfCurrentThreadQueueFullAndLevelMoreSpecificThanThreshold() throws Exception {
+ DiscardingAsyncEventRouter router = new DiscardingAsyncEventRouter(256, 0.5F, Level.WARN);
+
+ for (Level level : new Level[] {Level.ERROR, Level.FATAL, Level.OFF}) {
+ assertEquals(level.name(), EventRoute.SYNCHRONOUS, router.getRoute(currentThreadId(), level, 256, 0));
+ }
+ }
+
+ @Test
+ public void testGetDiscardCount() throws Exception {
+ DiscardingAsyncEventRouter router = new DiscardingAsyncEventRouter(4, 0F, Level.INFO);
+ assertEquals("initially", 0, DiscardingAsyncEventRouter.getDiscardCount(router));
+
+ assertEquals(EventRoute.DISCARD, router.getRoute(-1L, Level.INFO, 256, 0));
+ assertEquals("increase", 1, DiscardingAsyncEventRouter.getDiscardCount(router));
+
+ assertEquals(EventRoute.DISCARD, router.getRoute(-1L, Level.INFO, 256, 0));
+ assertEquals("increase", 2, DiscardingAsyncEventRouter.getDiscardCount(router));
+
+ assertEquals(EventRoute.DISCARD, router.getRoute(-1L, Level.INFO, 256, 0));
+ assertEquals("increase", 3, DiscardingAsyncEventRouter.getDiscardCount(router));
+ }
+}
\ No newline at end of file
[27/50] logging-log4j2 git commit: [LOG4J2-1232] Incorrect log
rotation in last week of year. Sort methods.
Posted by mi...@apache.org.
[LOG4J2-1232] Incorrect log rotation in last week of year. Sort methods.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/5644b132
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/5644b132
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/5644b132
Branch: refs/heads/LOG4J-1181
Commit: 5644b13228139ae22062b8590d1b1ee857a1f6b4
Parents: f28d3d8
Author: ggregory <gg...@apache.org>
Authored: Thu Dec 31 18:51:42 2015 -0800
Committer: ggregory <gg...@apache.org>
Committed: Thu Dec 31 18:51:42 2015 -0800
----------------------------------------------------------------------
.../appender/rolling/PatternProcessorTest.java | 244 +++++++++----------
1 file changed, 122 insertions(+), 122 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/5644b132/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessorTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessorTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessorTest.java
index c06b815..f366877 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessorTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessorTest.java
@@ -38,177 +38,143 @@ public class PatternProcessorTest {
}
@Test
- public void testGetNextTimeMonthlyReturnsFirstDayOfNextMonth() {
- final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM}.log.gz");
- final Calendar initial = Calendar.getInstance();
- initial.set(2014, Calendar.OCTOBER, 15, 10, 31, 59); // Oct 15th
- final long actual = pp.getNextTime(initial.getTimeInMillis(), 1, false);
+ public void testDontInterpretBackslashAsEscape() {
+ final PatternProcessor pp = new PatternProcessor("c:\\test\\new/app-%d{HH-mm-ss}.log");
+ final Calendar cal = Calendar.getInstance();
+ cal.set(Calendar.HOUR_OF_DAY, 16);
+ cal.set(Calendar.MINUTE, 02);
+ cal.set(Calendar.SECOND, 15);
- // We expect 1st day of next month
- final Calendar expected = Calendar.getInstance();
- expected.set(2014, Calendar.NOVEMBER, 1, 00, 00, 00);
- expected.set(Calendar.MILLISECOND, 0);
- assertEquals(format(expected.getTimeInMillis()), format(actual));
+ final StringBuilder buf = new StringBuilder();
+ pp.formatFileName(buf, cal.getTime(), 23);
+ assertEquals("c:\\test\\new/app-16-02-15.log", buf.toString());
}
@Test
- public void testGetNextTimeMonthlyReturnsFirstDayOfNextYear() {
- final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM}.log.gz");
+ public void testGetNextTimeHourlyReturnsFirstMinuteOfNextHour() {
+ final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM-dd-HH}.log.gz");
final Calendar initial = Calendar.getInstance();
- initial.set(2015, Calendar.DECEMBER, 28, 0, 0, 0);
+ initial.set(2014, Calendar.MARCH, 4, 10, 31, 59); // Tue, March 4, 2014, 10:31
final long actual = pp.getNextTime(initial.getTimeInMillis(), 1, false);
- // We expect 1st day of next month
+ // expect Wed, March 4, 2014, 11:00
final Calendar expected = Calendar.getInstance();
- expected.set(2016, Calendar.JANUARY, 1, 00, 00, 00);
+ expected.set(2014, Calendar.MARCH, 4, 11, 00, 00);
expected.set(Calendar.MILLISECOND, 0);
assertEquals(format(expected.getTimeInMillis()), format(actual));
}
@Test
- public void testGetNextTimeMonthlyReturnsFirstDayOfNextMonth2() {
- final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM}.log.gz");
+ public void testGetNextTimeHourlyReturnsFirstMinuteOfNextHour2() {
+ final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM-dd-HH}.log.gz");
final Calendar initial = Calendar.getInstance();
- initial.set(2014, Calendar.JANUARY, 31, 10, 31, 59); // 2014 Jan 31st
+ initial.set(2014, Calendar.MARCH, 4, 23, 31, 59); // Tue, March 4, 2014, 23:31
final long actual = pp.getNextTime(initial.getTimeInMillis(), 1, false);
- // Expect 1st of next month: 2014 Feb 1st
+ // expect Wed, March 5, 2014, 00:00
final Calendar expected = Calendar.getInstance();
- expected.set(2014, Calendar.FEBRUARY, 1, 00, 00, 00);
+ expected.set(2014, Calendar.MARCH, 5, 00, 00, 00);
expected.set(Calendar.MILLISECOND, 0);
assertEquals(format(expected.getTimeInMillis()), format(actual));
}
@Test
- public void testGetNextTimeMonthlyReturnsFirstDayOfNextMonth3() {
- final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM}.log.gz");
+ public void testGetNextTimeHourlyReturnsFirstMinuteOfNextYear() {
+ final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM-dd-HH}.log.gz");
final Calendar initial = Calendar.getInstance();
- initial.set(2014, Calendar.DECEMBER, 31, 10, 31, 59); // 2014 Dec 31st
+ initial.set(2015, Calendar.DECEMBER, 31, 23, 31, 59);
final long actual = pp.getNextTime(initial.getTimeInMillis(), 1, false);
- // Expect 1st of next month: 2015 Jan 1st
final Calendar expected = Calendar.getInstance();
- expected.set(2015, Calendar.JANUARY, 1, 00, 00, 00);
+ expected.set(2016, Calendar.JANUARY, 1, 0, 0, 0);
expected.set(Calendar.MILLISECOND, 0);
assertEquals(format(expected.getTimeInMillis()), format(actual));
}
@Test
- @Ignore("https://issues.apache.org/jira/browse/LOG4J2-1232")
- public void testGetNextTimeWeeklyReturnsFirstWeekInYear_US() {
- final Locale old = Locale.getDefault();
- Locale.setDefault(Locale.US); // force 1st day of the week to be Sunday
- try {
- final PatternProcessor pp = new PatternProcessor("logs/market_data_msg.log-%d{yyyy-MM-'W'W}");
- final Calendar initial = Calendar.getInstance();
- initial.set(2015, Calendar.DECEMBER, 28, 00, 00, 00); // Monday, December 28, 2015
- final long actual = pp.getNextTime(initial.getTimeInMillis(), 1, false);
-
- // expect Monday January 4, 2016
- final Calendar expected = Calendar.getInstance();
- expected.set(2016, Calendar.JANUARY, 4, 00, 00, 00);
- expected.set(Calendar.MILLISECOND, 0);
- assertEquals(format(expected.getTimeInMillis()), format(actual));
- } finally {
- Locale.setDefault(old);
- }
- }
-
- @Test
- public void testGetNextTimeWeeklyReturnsFirstDayOfNextWeek_US() {
- final Locale old = Locale.getDefault();
- Locale.setDefault(Locale.US); // force 1st day of the week to be Sunday
-
- try {
- final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM-W}.log.gz");
- final Calendar initial = Calendar.getInstance();
- initial.set(2014, Calendar.MARCH, 4, 10, 31, 59); // Tue, March 4, 2014
- final long actual = pp.getNextTime(initial.getTimeInMillis(), 1, false);
+ public void testGetNextTimeMillisecondlyReturnsNextMillisec() {
+ final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM-dd-HH-mm-ss.SSS}.log.gz");
+ final Calendar initial = Calendar.getInstance();
+ initial.set(2014, Calendar.MARCH, 4, 10, 31, 53); // Tue, March 4, 2014, 10:31:53.123
+ initial.set(Calendar.MILLISECOND, 123);
+ assertEquals("2014/03/04 10:31:53.123", format(initial.getTimeInMillis()));
+ final long actual = pp.getNextTime(initial.getTimeInMillis(), 1, false);
- // expect Sunday, March 9, 2014
- final Calendar expected = Calendar.getInstance();
- expected.set(2014, Calendar.MARCH, 9, 00, 00, 00);
- expected.set(Calendar.MILLISECOND, 0);
- assertEquals(format(expected.getTimeInMillis()), format(actual));
- } finally {
- Locale.setDefault(old);
- }
+ // expect Tue, March 4, 2014, 10:31:53.124
+ final Calendar expected = Calendar.getInstance();
+ expected.set(2014, Calendar.MARCH, 4, 10, 31, 53);
+ expected.set(Calendar.MILLISECOND, 124);
+ assertEquals(format(expected.getTimeInMillis()), format(actual));
}
@Test
- public void testGetNextTimeWeeklyReturnsFirstDayOfNextWeek_FRANCE() {
- final Locale old = Locale.getDefault();
- Locale.setDefault(Locale.FRANCE); // force 1st day of the week to be Monday
-
- try {
- final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM-W}.log.gz");
- final Calendar initial = Calendar.getInstance();
- initial.set(2014, Calendar.MARCH, 4, 10, 31, 59); // Tue, March 4, 2014
- final long actual = pp.getNextTime(initial.getTimeInMillis(), 1, false);
+ public void testGetNextTimeMinutelyReturnsFirstSecondOfNextMinute() {
+ final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM-dd-HH-mm}.log.gz");
+ final Calendar initial = Calendar.getInstance();
+ initial.set(2014, Calendar.MARCH, 4, 10, 31, 59); // Tue, March 4, 2014, 10:31
+ initial.set(Calendar.MILLISECOND, 0);
+ assertEquals("2014/03/04 10:31:59.000", format(initial.getTimeInMillis()));
+ final long actual = pp.getNextTime(initial.getTimeInMillis(), 1, false);
- // expect Monday, March 10, 2014
- final Calendar expected = Calendar.getInstance();
- expected.set(2014, Calendar.MARCH, 10, 00, 00, 00);
- expected.set(Calendar.MILLISECOND, 0);
- assertEquals(format(expected.getTimeInMillis()), format(actual));
- } finally {
- Locale.setDefault(old);
- }
+ // expect Tue, March 4, 2014, 10:32
+ final Calendar expected = Calendar.getInstance();
+ expected.set(2014, Calendar.MARCH, 4, 10, 32, 00);
+ expected.set(Calendar.MILLISECOND, 0);
+ assertEquals(format(expected.getTimeInMillis()), format(actual));
}
@Test
- public void testGetNextTimeHourlyReturnsFirstMinuteOfNextHour() {
- final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM-dd-HH}.log.gz");
+ public void testGetNextTimeMonthlyReturnsFirstDayOfNextMonth() {
+ final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM}.log.gz");
final Calendar initial = Calendar.getInstance();
- initial.set(2014, Calendar.MARCH, 4, 10, 31, 59); // Tue, March 4, 2014, 10:31
+ initial.set(2014, Calendar.OCTOBER, 15, 10, 31, 59); // Oct 15th
final long actual = pp.getNextTime(initial.getTimeInMillis(), 1, false);
- // expect Wed, March 4, 2014, 11:00
+ // We expect 1st day of next month
final Calendar expected = Calendar.getInstance();
- expected.set(2014, Calendar.MARCH, 4, 11, 00, 00);
+ expected.set(2014, Calendar.NOVEMBER, 1, 00, 00, 00);
expected.set(Calendar.MILLISECOND, 0);
assertEquals(format(expected.getTimeInMillis()), format(actual));
}
@Test
- public void testGetNextTimeHourlyReturnsFirstMinuteOfNextYear() {
- final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM-dd-HH}.log.gz");
+ public void testGetNextTimeMonthlyReturnsFirstDayOfNextMonth2() {
+ final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM}.log.gz");
final Calendar initial = Calendar.getInstance();
- initial.set(2015, Calendar.DECEMBER, 31, 23, 31, 59);
+ initial.set(2014, Calendar.JANUARY, 31, 10, 31, 59); // 2014 Jan 31st
final long actual = pp.getNextTime(initial.getTimeInMillis(), 1, false);
+ // Expect 1st of next month: 2014 Feb 1st
final Calendar expected = Calendar.getInstance();
- expected.set(2016, Calendar.JANUARY, 1, 0, 0, 0);
+ expected.set(2014, Calendar.FEBRUARY, 1, 00, 00, 00);
expected.set(Calendar.MILLISECOND, 0);
assertEquals(format(expected.getTimeInMillis()), format(actual));
}
@Test
- public void testGetNextTimeHourlyReturnsFirstMinuteOfNextHour2() {
- final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM-dd-HH}.log.gz");
+ public void testGetNextTimeMonthlyReturnsFirstDayOfNextMonth3() {
+ final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM}.log.gz");
final Calendar initial = Calendar.getInstance();
- initial.set(2014, Calendar.MARCH, 4, 23, 31, 59); // Tue, March 4, 2014, 23:31
+ initial.set(2014, Calendar.DECEMBER, 31, 10, 31, 59); // 2014 Dec 31st
final long actual = pp.getNextTime(initial.getTimeInMillis(), 1, false);
- // expect Wed, March 5, 2014, 00:00
+ // Expect 1st of next month: 2015 Jan 1st
final Calendar expected = Calendar.getInstance();
- expected.set(2014, Calendar.MARCH, 5, 00, 00, 00);
+ expected.set(2015, Calendar.JANUARY, 1, 00, 00, 00);
expected.set(Calendar.MILLISECOND, 0);
assertEquals(format(expected.getTimeInMillis()), format(actual));
}
@Test
- public void testGetNextTimeMinutelyReturnsFirstSecondOfNextMinute() {
- final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM-dd-HH-mm}.log.gz");
+ public void testGetNextTimeMonthlyReturnsFirstDayOfNextYear() {
+ final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM}.log.gz");
final Calendar initial = Calendar.getInstance();
- initial.set(2014, Calendar.MARCH, 4, 10, 31, 59); // Tue, March 4, 2014, 10:31
- initial.set(Calendar.MILLISECOND, 0);
- assertEquals("2014/03/04 10:31:59.000", format(initial.getTimeInMillis()));
+ initial.set(2015, Calendar.DECEMBER, 28, 0, 0, 0);
final long actual = pp.getNextTime(initial.getTimeInMillis(), 1, false);
- // expect Tue, March 4, 2014, 10:32
+ // We expect 1st day of next month
final Calendar expected = Calendar.getInstance();
- expected.set(2014, Calendar.MARCH, 4, 10, 32, 00);
+ expected.set(2016, Calendar.JANUARY, 1, 00, 00, 00);
expected.set(Calendar.MILLISECOND, 0);
assertEquals(format(expected.getTimeInMillis()), format(actual));
}
@@ -230,31 +196,65 @@ public class PatternProcessorTest {
}
@Test
- public void testGetNextTimeMillisecondlyReturnsNextMillisec() {
- final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM-dd-HH-mm-ss.SSS}.log.gz");
- final Calendar initial = Calendar.getInstance();
- initial.set(2014, Calendar.MARCH, 4, 10, 31, 53); // Tue, March 4, 2014, 10:31:53.123
- initial.set(Calendar.MILLISECOND, 123);
- assertEquals("2014/03/04 10:31:53.123", format(initial.getTimeInMillis()));
- final long actual = pp.getNextTime(initial.getTimeInMillis(), 1, false);
+ public void testGetNextTimeWeeklyReturnsFirstDayOfNextWeek_FRANCE() {
+ final Locale old = Locale.getDefault();
+ Locale.setDefault(Locale.FRANCE); // force 1st day of the week to be Monday
- // expect Tue, March 4, 2014, 10:31:53.124
- final Calendar expected = Calendar.getInstance();
- expected.set(2014, Calendar.MARCH, 4, 10, 31, 53);
- expected.set(Calendar.MILLISECOND, 124);
- assertEquals(format(expected.getTimeInMillis()), format(actual));
+ try {
+ final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM-W}.log.gz");
+ final Calendar initial = Calendar.getInstance();
+ initial.set(2014, Calendar.MARCH, 4, 10, 31, 59); // Tue, March 4, 2014
+ final long actual = pp.getNextTime(initial.getTimeInMillis(), 1, false);
+
+ // expect Monday, March 10, 2014
+ final Calendar expected = Calendar.getInstance();
+ expected.set(2014, Calendar.MARCH, 10, 00, 00, 00);
+ expected.set(Calendar.MILLISECOND, 0);
+ assertEquals(format(expected.getTimeInMillis()), format(actual));
+ } finally {
+ Locale.setDefault(old);
+ }
}
@Test
- public void testDontInterpretBackslashAsEscape() {
- final PatternProcessor pp = new PatternProcessor("c:\\test\\new/app-%d{HH-mm-ss}.log");
- final Calendar cal = Calendar.getInstance();
- cal.set(Calendar.HOUR_OF_DAY, 16);
- cal.set(Calendar.MINUTE, 02);
- cal.set(Calendar.SECOND, 15);
+ public void testGetNextTimeWeeklyReturnsFirstDayOfNextWeek_US() {
+ final Locale old = Locale.getDefault();
+ Locale.setDefault(Locale.US); // force 1st day of the week to be Sunday
- final StringBuilder buf = new StringBuilder();
- pp.formatFileName(buf, cal.getTime(), 23);
- assertEquals("c:\\test\\new/app-16-02-15.log", buf.toString());
+ try {
+ final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM-W}.log.gz");
+ final Calendar initial = Calendar.getInstance();
+ initial.set(2014, Calendar.MARCH, 4, 10, 31, 59); // Tue, March 4, 2014
+ final long actual = pp.getNextTime(initial.getTimeInMillis(), 1, false);
+
+ // expect Sunday, March 9, 2014
+ final Calendar expected = Calendar.getInstance();
+ expected.set(2014, Calendar.MARCH, 9, 00, 00, 00);
+ expected.set(Calendar.MILLISECOND, 0);
+ assertEquals(format(expected.getTimeInMillis()), format(actual));
+ } finally {
+ Locale.setDefault(old);
+ }
+ }
+
+ @Test
+ @Ignore("https://issues.apache.org/jira/browse/LOG4J2-1232")
+ public void testGetNextTimeWeeklyReturnsFirstWeekInYear_US() {
+ final Locale old = Locale.getDefault();
+ Locale.setDefault(Locale.US); // force 1st day of the week to be Sunday
+ try {
+ final PatternProcessor pp = new PatternProcessor("logs/market_data_msg.log-%d{yyyy-MM-'W'W}");
+ final Calendar initial = Calendar.getInstance();
+ initial.set(2015, Calendar.DECEMBER, 28, 00, 00, 00); // Monday, December 28, 2015
+ final long actual = pp.getNextTime(initial.getTimeInMillis(), 1, false);
+
+ // expect Monday January 4, 2016
+ final Calendar expected = Calendar.getInstance();
+ expected.set(2016, Calendar.JANUARY, 4, 00, 00, 00);
+ expected.set(Calendar.MILLISECOND, 0);
+ assertEquals(format(expected.getTimeInMillis()), format(actual));
+ } finally {
+ Locale.setDefault(old);
+ }
}
}
[44/50] logging-log4j2 git commit: [LOG4J2-1244] Make header and
footer values customizable in JSONLayout. [LOG4J2-1245] Make CSV Layout
header and footers accept patterns.
Posted by mi...@apache.org.
[LOG4J2-1244] Make header and footer values customizable in JSONLayout.
[LOG4J2-1245] Make CSV Layout header and footers accept patterns.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/75d33d96
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/75d33d96
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/75d33d96
Branch: refs/heads/LOG4J-1181
Commit: 75d33d96ac00356014cf11f8ad9e8c6ead4db37a
Parents: 5b1404b
Author: ggregory <gg...@apache.org>
Authored: Tue Jan 5 18:57:38 2016 -0800
Committer: ggregory <gg...@apache.org>
Committed: Tue Jan 5 18:57:38 2016 -0800
----------------------------------------------------------------------
.../log4j/core/layout/AbstractCsvLayout.java | 9 +-
.../core/layout/AbstractJacksonLayout.java | 11 +-
.../log4j/core/layout/AbstractLayout.java | 45 +++++-
.../log4j/core/layout/AbstractStringLayout.java | 158 ++++++++++++++-----
.../log4j/core/layout/CsvLogEventLayout.java | 15 +-
.../log4j/core/layout/CsvParameterLayout.java | 15 +-
.../logging/log4j/core/layout/JsonLayout.java | 51 ++++--
.../log4j/core/layout/PatternLayout.java | 52 +-----
.../log4j/core/layout/SerializedLayout.java | 2 +-
.../logging/log4j/core/layout/XmlLayout.java | 2 +-
.../logging/log4j/core/net/SmtpManager.java | 4 +-
.../core/layout/CsvLogEventLayoutTest.java | 44 +++++-
.../core/layout/CsvParameterLayoutTest.java | 4 +-
.../log4j/core/layout/JsonLayoutTest.java | 17 +-
.../net/server/AbstractSocketServerTest.java | 2 +-
src/changes/changes.xml | 6 +
16 files changed, 295 insertions(+), 142 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/75d33d96/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractCsvLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractCsvLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractCsvLayout.java
index ae55447..c5b0e90 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractCsvLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractCsvLayout.java
@@ -20,7 +20,7 @@ import java.nio.charset.Charset;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.QuoteMode;
-import org.apache.logging.log4j.core.util.StringEncoder;
+import org.apache.logging.log4j.core.config.Configuration;
/**
* A superclass for Comma-Separated Value (CSV) layouts.
@@ -38,9 +38,10 @@ public abstract class AbstractCsvLayout extends AbstractStringLayout {
private final CSVFormat format;
- protected AbstractCsvLayout(final Charset charset, final CSVFormat csvFormat, final String header,
- final String footer) {
- super(charset, StringEncoder.toBytes(header, charset), StringEncoder.toBytes(footer, charset));
+ protected AbstractCsvLayout(final Configuration config, final Charset charset, final CSVFormat csvFormat,
+ final String header, final String footer) {
+ super(config, charset, PatternLayout.createSerializer(config, null, header, null, null, false, false),
+ PatternLayout.createSerializer(config, null, footer, null, null, false, false));
this.format = csvFormat;
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/75d33d96/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
index 3b122e1..ced02e2 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
@@ -21,6 +21,7 @@ import java.io.Writer;
import java.nio.charset.Charset;
import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.util.StringBuilderWriter;
import org.apache.logging.log4j.util.Strings;
@@ -39,8 +40,10 @@ abstract class AbstractJacksonLayout extends AbstractStringLayout {
protected final boolean compact;
protected final boolean complete;
- protected AbstractJacksonLayout(final ObjectWriter objectWriter, final Charset charset, final boolean compact, final boolean complete, final boolean eventEol) {
- super(charset);
+ protected AbstractJacksonLayout(final Configuration config, final ObjectWriter objectWriter, final Charset charset,
+ final boolean compact, final boolean complete, final boolean eventEol, final Serializer headerSerializer,
+ final Serializer footerSerializer) {
+ super(config, charset, headerSerializer, footerSerializer);
this.objectWriter = objectWriter;
this.compact = compact;
this.complete = complete;
@@ -55,7 +58,7 @@ abstract class AbstractJacksonLayout extends AbstractStringLayout {
*/
@Override
public String toSerializable(final LogEvent event) {
- StringBuilderWriter writer = new StringBuilderWriter();
+ final StringBuilderWriter writer = new StringBuilderWriter();
try {
toSerializable(event, writer);
return writer.toString();
@@ -66,7 +69,7 @@ abstract class AbstractJacksonLayout extends AbstractStringLayout {
}
}
- public void toSerializable(final LogEvent event, Writer writer)
+ public void toSerializable(final LogEvent event, final Writer writer)
throws JsonGenerationException, JsonMappingException, IOException {
objectWriter.writeValue(writer, event);
writer.write(eol);
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/75d33d96/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractLayout.java
index 9c5166e..fae6349 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractLayout.java
@@ -22,13 +22,14 @@ import java.util.Map;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.Layout;
+import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.status.StatusLogger;
/**
* Abstract base class for Layouts.
*
* @param <T>
- * The Class that the Layout will format the LogEvent into.
+ * The Class that the Layout will format the LogEvent into.
*/
public abstract class AbstractLayout<T extends Serializable> implements Layout<T>, Serializable {
@@ -40,9 +41,14 @@ public abstract class AbstractLayout<T extends Serializable> implements Layout<T
private static final long serialVersionUID = 1L;
/**
- * The header to include when the stream is opened. May be null.
+ * The current Configuration.
*/
- protected final byte[] header;
+ protected final Configuration configuration;
+
+ /**
+ * The number of events successfully processed by this layout.
+ */
+ protected long eventCount;
/**
* The footer to add when the stream is closed. May be null.
@@ -50,24 +56,47 @@ public abstract class AbstractLayout<T extends Serializable> implements Layout<T
protected final byte[] footer;
/**
- * The count of events successfully processed by this layout.
+ * The header to include when the stream is opened. May be null.
*/
- protected long eventCount;
+ protected final byte[] header;
/**
* Constructs a layout with an optional header and footer.
*
+ * @param configuration
+ * The configuration
* @param header
- * The header to include when the stream is opened. May be null.
+ * The header to include when the stream is opened. May be null.
* @param footer
- * The footer to add when the stream is closed. May be null.
+ * The footer to add when the stream is closed. May be null.
+ * @deprecated Use {@link #AbstractLayout(Configuration, byte[], byte[])}
*/
+ @Deprecated
public AbstractLayout(final byte[] header, final byte[] footer) {
+ this(null, header, footer);
+ }
+
+ /**
+ * Constructs a layout with an optional header and footer.
+ *
+ * @param configuration
+ * The configuration
+ * @param header
+ * The header to include when the stream is opened. May be null.
+ * @param footer
+ * The footer to add when the stream is closed. May be null.
+ */
+ public AbstractLayout(final Configuration configuration, final byte[] header, final byte[] footer) {
super();
+ this.configuration = configuration;
this.header = header;
this.footer = footer;
}
+ public Configuration getConfiguration() {
+ return configuration;
+ }
+
@Override
public Map<String, String> getContentFormat() {
return new HashMap<>();
@@ -92,7 +121,7 @@ public abstract class AbstractLayout<T extends Serializable> implements Layout<T
public byte[] getHeader() {
return header;
}
-
+
protected void markEvent() {
eventCount++;
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/75d33d96/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java
index 96a80a5..91e21ef 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java
@@ -25,7 +25,10 @@ import java.nio.charset.StandardCharsets;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.StringLayout;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.LoggerConfig;
import org.apache.logging.log4j.core.util.StringEncoder;
+import org.apache.logging.log4j.util.Strings;
/**
* Abstract base class for Layouts that result in a String.
@@ -39,41 +42,19 @@ import org.apache.logging.log4j.core.util.StringEncoder;
*/
public abstract class AbstractStringLayout extends AbstractLayout<String> implements StringLayout {
+ public interface Serializer {
+
+ String toSerializable(final LogEvent event);
+ }
+
/**
* Default length for new StringBuilder instances: {@value} .
*/
protected static final int DEFAULT_STRING_BUILDER_SIZE = 1024;
- private final static ThreadLocal<StringBuilder> threadLocal = new ThreadLocal<>();
-
private static final long serialVersionUID = 1L;
- /**
- * The charset for the formatted message.
- */
- // LOG4J2-1099: charset cannot be final due to serialization needs, so we serialize as charset name instead
- private transient Charset charset;
- private final String charsetName;
- private final boolean useCustomEncoding;
-
- protected AbstractStringLayout(final Charset charset) {
- this(charset, null, null);
- }
-
- /**
- * Builds a new layout.
- * @param charset the charset used to encode the header bytes, footer bytes and anything else that needs to be
- * converted from strings to bytes.
- * @param header the header bytes
- * @param footer the footer bytes
- */
- protected AbstractStringLayout(final Charset charset, final byte[] header, final byte[] footer) {
- super(header, footer);
- this.charset = charset == null ? StandardCharsets.UTF_8 : charset;
- this.charsetName = this.charset.name();
- useCustomEncoding = isPreJava8()
- && (StandardCharsets.ISO_8859_1.equals(charset) || StandardCharsets.US_ASCII.equals(charset));
- }
+ private final static ThreadLocal<StringBuilder> threadLocal = new ThreadLocal<>();
/**
* Returns a {@code StringBuilder} that this Layout implementation can use to write the formatted log event to.
@@ -89,28 +70,68 @@ public abstract class AbstractStringLayout extends AbstractLayout<String> implem
result.setLength(0);
return result;
}
-
// LOG4J2-1151: If the built-in JDK 8 encoders are available we should use them.
private static boolean isPreJava8() {
final String version = System.getProperty("java.version");
final String[] parts = version.split("\\.");
try {
- int major = Integer.parseInt(parts[1]);
+ final int major = Integer.parseInt(parts[1]);
return major < 8;
- } catch (Exception ex) {
+ } catch (final Exception ex) {
return true;
}
}
+ /**
+ * The charset for the formatted message.
+ */
+ // LOG4J2-1099: charset cannot be final due to serialization needs, so we serialize as charset name instead
+ private transient Charset charset;
- private void writeObject(final ObjectOutputStream out) throws IOException {
- out.defaultWriteObject();
- out.writeUTF(charset.name());
+ private final String charsetName;
+
+ private final Serializer footerSerializer;
+
+ private final Serializer headerSerializer;
+
+ private final boolean useCustomEncoding;
+
+ protected AbstractStringLayout(final Charset charset) {
+ this(charset, (byte[]) null, (byte[]) null);
+ }
+
+ /**
+ * Builds a new layout.
+ * @param charset the charset used to encode the header bytes, footer bytes and anything else that needs to be
+ * converted from strings to bytes.
+ * @param header the header bytes
+ * @param footer the footer bytes
+ */
+ protected AbstractStringLayout(final Charset charset, final byte[] header, final byte[] footer) {
+ super(null, header, footer);
+ this.headerSerializer = null;
+ this.footerSerializer = null;
+ this.charset = charset == null ? StandardCharsets.UTF_8 : charset;
+ this.charsetName = this.charset.name();
+ useCustomEncoding = isPreJava8()
+ && (StandardCharsets.ISO_8859_1.equals(charset) || StandardCharsets.US_ASCII.equals(charset));
}
- private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
- in.defaultReadObject();
- final String csName = in.readUTF();
- charset = Charset.forName(csName);
+ /**
+ * Builds a new layout.
+ * @param Configuration config the configuration
+ * @param charset the charset used to encode the header bytes, footer bytes and anything else that needs to be
+ * converted from strings to bytes.
+ * @param header the header bytes serializer
+ * @param footer the footer bytes serializer
+ */
+ protected AbstractStringLayout(final Configuration config, final Charset charset, final Serializer headerSerializer, final Serializer footerSerializer) {
+ super(config, null, null);
+ this.headerSerializer = headerSerializer;
+ this.footerSerializer = footerSerializer;
+ this.charset = charset == null ? StandardCharsets.UTF_8 : charset;
+ this.charsetName = this.charset.name();
+ useCustomEncoding = isPreJava8()
+ && (StandardCharsets.ISO_8859_1.equals(charset) || StandardCharsets.US_ASCII.equals(charset));
}
protected byte[] getBytes(final String s) {
@@ -119,7 +140,7 @@ public abstract class AbstractStringLayout extends AbstractLayout<String> implem
}
try { // LOG4J2-935: String.getBytes(String) gives better performance
return s.getBytes(charsetName);
- } catch (UnsupportedEncodingException e) {
+ } catch (final UnsupportedEncodingException e) {
return s.getBytes(charset);
}
}
@@ -129,6 +150,7 @@ public abstract class AbstractStringLayout extends AbstractLayout<String> implem
return charset;
}
+
/**
* @return The default content type for Strings.
*/
@@ -138,6 +160,59 @@ public abstract class AbstractStringLayout extends AbstractLayout<String> implem
}
/**
+ * Returns the footer, if one is available.
+ *
+ * @return A byte array containing the footer.
+ */
+ @Override
+ public byte[] getFooter() {
+ return serializeToBytes(footerSerializer, super.getFooter());
+ }
+
+ public Serializer getFooterSerializer() {
+ return footerSerializer;
+ }
+
+ /**
+ * Returns the header, if one is available.
+ *
+ * @return A byte array containing the header.
+ */
+ @Override
+ public byte[] getHeader() {
+ return serializeToBytes(headerSerializer, super.getHeader());
+ }
+
+ public Serializer getHeaderSerializer() {
+ return headerSerializer;
+ }
+
+ private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
+ in.defaultReadObject();
+ final String csName = in.readUTF();
+ charset = Charset.forName(csName);
+ }
+
+ protected byte[] serializeToBytes(final Serializer serializer, byte[] defaultValue) {
+ final String serializable = serializeToString(serializer);
+ if (serializer == null) {
+ return defaultValue;
+ }
+ return StringEncoder.toBytes(serializable, getCharset());
+ }
+
+ protected String serializeToString(final Serializer serializer) {
+ if (serializer == null) {
+ return null;
+ }
+ final LoggerConfig rootLogger = getConfiguration().getRootLogger();
+ // Using "" for the FQCN, does it matter?
+ final LogEvent logEvent = rootLogger.getLogEventFactory().createEvent(rootLogger.getName(), null, Strings.EMPTY,
+ rootLogger.getLevel(), null, null, null);
+ return serializer.toSerializable(logEvent);
+ }
+
+ /**
* Formats the Log Event as a byte array.
*
* @param event The Log Event.
@@ -147,5 +222,10 @@ public abstract class AbstractStringLayout extends AbstractLayout<String> implem
public byte[] toByteArray(final LogEvent event) {
return getBytes(toSerializable(event));
}
+
+ private void writeObject(final ObjectOutputStream out) throws IOException {
+ out.defaultWriteObject();
+ out.writeUTF(charset.name());
+ }
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/75d33d96/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/CsvLogEventLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/CsvLogEventLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/CsvLogEventLayout.java
index 9b737fe..dd751f9 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/CsvLogEventLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/CsvLogEventLayout.java
@@ -24,9 +24,11 @@ import org.apache.commons.csv.CSVPrinter;
import org.apache.commons.csv.QuoteMode;
import org.apache.logging.log4j.core.Layout;
import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.Node;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
import org.apache.logging.log4j.core.config.plugins.PluginFactory;
import org.apache.logging.log4j.status.StatusLogger;
@@ -43,16 +45,17 @@ public class CsvLogEventLayout extends AbstractCsvLayout {
private static final long serialVersionUID = 1L;
public static CsvLogEventLayout createDefaultLayout() {
- return new CsvLogEventLayout(Charset.forName(DEFAULT_CHARSET), CSVFormat.valueOf(DEFAULT_FORMAT), null, null);
+ return new CsvLogEventLayout(null, Charset.forName(DEFAULT_CHARSET), CSVFormat.valueOf(DEFAULT_FORMAT), null, null);
}
public static CsvLogEventLayout createLayout(final CSVFormat format) {
- return new CsvLogEventLayout(Charset.forName(DEFAULT_CHARSET), format, null, null);
+ return new CsvLogEventLayout(null, Charset.forName(DEFAULT_CHARSET), format, null, null);
}
@PluginFactory
public static CsvLogEventLayout createLayout(
// @formatter:off
+ @PluginConfiguration final Configuration config,
@PluginAttribute(value = "format", defaultString = DEFAULT_FORMAT) final String format,
@PluginAttribute("delimiter") final Character delimiter,
@PluginAttribute("escape") final Character escape,
@@ -61,17 +64,17 @@ public class CsvLogEventLayout extends AbstractCsvLayout {
@PluginAttribute("nullString") final String nullString,
@PluginAttribute("recordSeparator") final String recordSeparator,
@PluginAttribute(value = "charset", defaultString = DEFAULT_CHARSET) final Charset charset,
- @PluginAttribute("header") final String header,
+ @PluginAttribute("header") final String header,
@PluginAttribute("footer") final String footer)
// @formatter:on
{
final CSVFormat csvFormat = createFormat(format, delimiter, escape, quote, quoteMode, nullString, recordSeparator);
- return new CsvLogEventLayout(charset, csvFormat, header, footer);
+ return new CsvLogEventLayout(config, charset, csvFormat, header, footer);
}
- protected CsvLogEventLayout(final Charset charset, final CSVFormat csvFormat, final String header, final String footer) {
- super(charset, csvFormat, header, footer);
+ protected CsvLogEventLayout(final Configuration config, final Charset charset, final CSVFormat csvFormat, final String header, final String footer) {
+ super(config, charset, csvFormat, header, footer);
}
@Override
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/75d33d96/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/CsvParameterLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/CsvParameterLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/CsvParameterLayout.java
index fb43964..324a08a 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/CsvParameterLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/CsvParameterLayout.java
@@ -24,9 +24,11 @@ import org.apache.commons.csv.CSVPrinter;
import org.apache.commons.csv.QuoteMode;
import org.apache.logging.log4j.core.Layout;
import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.Node;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
import org.apache.logging.log4j.core.config.plugins.PluginFactory;
import org.apache.logging.log4j.message.Message;
import org.apache.logging.log4j.status.StatusLogger;
@@ -52,16 +54,17 @@ public class CsvParameterLayout extends AbstractCsvLayout {
private static final long serialVersionUID = 1L;
public static AbstractCsvLayout createDefaultLayout() {
- return new CsvParameterLayout(Charset.forName(DEFAULT_CHARSET), CSVFormat.valueOf(DEFAULT_FORMAT), null, null);
+ return new CsvParameterLayout(null, Charset.forName(DEFAULT_CHARSET), CSVFormat.valueOf(DEFAULT_FORMAT), null, null);
}
public static AbstractCsvLayout createLayout(final CSVFormat format) {
- return new CsvParameterLayout(Charset.forName(DEFAULT_CHARSET), format, null, null);
+ return new CsvParameterLayout(null, Charset.forName(DEFAULT_CHARSET), format, null, null);
}
@PluginFactory
public static AbstractCsvLayout createLayout(
// @formatter:off
+ @PluginConfiguration final Configuration config,
@PluginAttribute(value = "format", defaultString = DEFAULT_FORMAT) final String format,
@PluginAttribute("delimiter") final Character delimiter,
@PluginAttribute("escape") final Character escape,
@@ -70,17 +73,17 @@ public class CsvParameterLayout extends AbstractCsvLayout {
@PluginAttribute("nullString") final String nullString,
@PluginAttribute("recordSeparator") final String recordSeparator,
@PluginAttribute(value = "charset", defaultString = DEFAULT_CHARSET) final Charset charset,
- @PluginAttribute("header") final String header,
+ @PluginAttribute("header") final String header,
@PluginAttribute("footer") final String footer)
// @formatter:on
{
final CSVFormat csvFormat = createFormat(format, delimiter, escape, quote, quoteMode, nullString, recordSeparator);
- return new CsvParameterLayout(charset, csvFormat, header, footer);
+ return new CsvParameterLayout(config, charset, csvFormat, header, footer);
}
- public CsvParameterLayout(final Charset charset, final CSVFormat csvFormat, final String header, final String footer) {
- super(charset, csvFormat, header, footer);
+ public CsvParameterLayout(final Configuration config, final Charset charset, final CSVFormat csvFormat, final String header, final String footer) {
+ super(config, charset, csvFormat, header, footer);
}
@Override
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/75d33d96/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java
index e403731..fe1a3b4 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java
@@ -25,9 +25,12 @@ import java.util.Map;
import org.apache.logging.log4j.core.Layout;
import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.DefaultConfiguration;
import org.apache.logging.log4j.core.config.Node;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
import org.apache.logging.log4j.core.config.plugins.PluginFactory;
/**
@@ -798,14 +801,21 @@ import org.apache.logging.log4j.core.config.plugins.PluginFactory;
@Plugin(name = "JsonLayout", category = Node.CATEGORY, elementType = Layout.ELEMENT_TYPE, printObject = true)
public final class JsonLayout extends AbstractJacksonLayout {
+ private static final String DEFAULT_FOOTER = "]";
+
+ private static final String DEFAULT_HEADER = "[";
+
static final String CONTENT_TYPE = "application/json";
private static final long serialVersionUID = 1L;
- protected JsonLayout(final boolean locationInfo, final boolean properties, final boolean complete,
- final boolean compact, final boolean eventEol, final Charset charset) {
- super(new JacksonFactory.JSON().newWriter(locationInfo, properties, compact), charset, compact, complete,
- eventEol);
+ protected JsonLayout(final Configuration config, final boolean locationInfo, final boolean properties,
+ final boolean complete, final boolean compact, final boolean eventEol, final String headerPattern,
+ final String footerPattern, final Charset charset) {
+ super(config, new JacksonFactory.JSON().newWriter(locationInfo, properties, compact), charset, compact,
+ complete, eventEol,
+ PatternLayout.createSerializer(config, null, headerPattern, DEFAULT_HEADER, null, false, false),
+ PatternLayout.createSerializer(config, null, footerPattern, DEFAULT_FOOTER, null, false, false));
}
/**
@@ -819,7 +829,10 @@ public final class JsonLayout extends AbstractJacksonLayout {
return null;
}
final StringBuilder buf = new StringBuilder();
- buf.append('[');
+ final String str = serializeToString(getHeaderSerializer());
+ if (str != null) {
+ buf.append(str);
+ }
buf.append(this.eol);
return getBytes(buf.toString());
}
@@ -834,7 +847,14 @@ public final class JsonLayout extends AbstractJacksonLayout {
if (!this.complete) {
return null;
}
- return getBytes(this.eol + ']' + this.eol);
+ final StringBuilder buf = new StringBuilder();
+ buf.append(this.eol);
+ final String str = serializeToString(getFooterSerializer());
+ if (str != null) {
+ buf.append(str);
+ }
+ buf.append(this.eol);
+ return getBytes(buf.toString());
}
@Override
@@ -854,7 +874,8 @@ public final class JsonLayout extends AbstractJacksonLayout {
/**
* Creates a JSON Layout.
- *
+ * @param config
+ * The plugin configuration.
* @param locationInfo
* If "true", includes the location information in the generated JSON.
* @param properties
@@ -866,6 +887,11 @@ public final class JsonLayout extends AbstractJacksonLayout {
* @param eventEol
* If "true", forces an EOL after each log event (even if compact is "true"), defaults to "false". This
* allows one even per line, even in compact mode.
+ * @param headerPattern
+ * The header pattern, defaults to {@code "["} if null.
+ * @param footerPattern
+ * The header pattern, defaults to {@code "]"} if null.
+ * @param footerPattern
* @param charset
* The character set to use, if {@code null}, uses "UTF-8".
* @return A JSON Layout.
@@ -873,28 +899,31 @@ public final class JsonLayout extends AbstractJacksonLayout {
@PluginFactory
public static AbstractJacksonLayout createLayout(
// @formatter:off
+ @PluginConfiguration final Configuration config,
@PluginAttribute(value = "locationInfo", defaultBoolean = false) final boolean locationInfo,
@PluginAttribute(value = "properties", defaultBoolean = false) final boolean properties,
@PluginAttribute(value = "complete", defaultBoolean = false) final boolean complete,
@PluginAttribute(value = "compact", defaultBoolean = false) final boolean compact,
@PluginAttribute(value = "eventEol", defaultBoolean = false) final boolean eventEol,
+ @PluginAttribute(value = "header", defaultString = DEFAULT_HEADER) final String headerPattern,
+ @PluginAttribute(value = "footer", defaultString = DEFAULT_FOOTER) final String footerPattern,
@PluginAttribute(value = "charset", defaultString = "UTF-8") final Charset charset
// @formatter:on
) {
- return new JsonLayout(locationInfo, properties, complete, compact, eventEol, charset);
+ return new JsonLayout(config, locationInfo, properties, complete, compact, eventEol, headerPattern, footerPattern, charset);
}
/**
- * Creates a JSON Layout using the default settings.
+ * Creates a JSON Layout using the default settings. Useful for testing.
*
* @return A JSON Layout.
*/
public static AbstractJacksonLayout createDefaultLayout() {
- return new JsonLayout(false, false, false, false, false, StandardCharsets.UTF_8);
+ return new JsonLayout(new DefaultConfiguration(), false, false, false, false, false, DEFAULT_HEADER, DEFAULT_FOOTER, StandardCharsets.UTF_8);
}
@Override
- public void toSerializable(final LogEvent event, Writer writer) throws IOException {
+ public void toSerializable(final LogEvent event, final Writer writer) throws IOException {
if (complete && eventCount > 0) {
writer.append(", ");
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/75d33d96/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java
index 0503fc8..518f6a4 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java
@@ -26,7 +26,6 @@ import org.apache.logging.log4j.core.Layout;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.DefaultConfiguration;
-import org.apache.logging.log4j.core.config.LoggerConfig;
import org.apache.logging.log4j.core.config.Node;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
@@ -39,7 +38,6 @@ import org.apache.logging.log4j.core.pattern.LogEventPatternConverter;
import org.apache.logging.log4j.core.pattern.PatternFormatter;
import org.apache.logging.log4j.core.pattern.PatternParser;
import org.apache.logging.log4j.core.pattern.RegexReplacement;
-import org.apache.logging.log4j.core.util.StringEncoder;
import org.apache.logging.log4j.util.Strings;
/**
@@ -89,15 +87,6 @@ public final class PatternLayout extends AbstractStringLayout {
private final Serializer eventSerializer;
- private final Serializer headerSerializer;
-
- private final Serializer footerSerializer;
-
- /**
- * The current Configuration.
- */
- private final Configuration config;
-
/**
* Constructs a EnhancedPatternLayout using the supplied conversion pattern.
*
@@ -116,16 +105,15 @@ public final class PatternLayout extends AbstractStringLayout {
private PatternLayout(final Configuration config, final RegexReplacement replace, final String eventPattern,
final PatternSelector patternSelector, final Charset charset, final boolean alwaysWriteExceptions,
final boolean noConsoleNoAnsi, final String headerPattern, final String footerPattern) {
- super(charset, StringEncoder.toBytes(headerPattern, charset), StringEncoder.toBytes(footerPattern, charset));
+ super(config, charset,
+ createSerializer(config, replace, headerPattern, null, patternSelector, alwaysWriteExceptions,
+ noConsoleNoAnsi),
+ createSerializer(config, replace, footerPattern, null, patternSelector, alwaysWriteExceptions,
+ noConsoleNoAnsi));
this.conversionPattern = eventPattern;
this.patternSelector = patternSelector;
- this.config = config;
- this.eventSerializer = createSerializer(config, replace, eventPattern, DEFAULT_CONVERSION_PATTERN, patternSelector,
- alwaysWriteExceptions, noConsoleNoAnsi);
- this.headerSerializer = createSerializer(config, replace, headerPattern, null, patternSelector,
- alwaysWriteExceptions, noConsoleNoAnsi);
- this.footerSerializer = createSerializer(config, replace, footerPattern, null, patternSelector,
- alwaysWriteExceptions, noConsoleNoAnsi);
+ this.eventSerializer = createSerializer(config, replace, eventPattern, DEFAULT_CONVERSION_PATTERN,
+ patternSelector, alwaysWriteExceptions, noConsoleNoAnsi);
}
public static Serializer createSerializer(final Configuration configuration, final RegexReplacement replace,
@@ -148,27 +136,6 @@ public final class PatternLayout extends AbstractStringLayout {
return new PatternSelectorSerializer(patternSelector, replace);
}
- @Override
- public byte[] getHeader() {
- return serializeHeaderFooter(headerSerializer);
- }
-
- @Override
- public byte[] getFooter() {
- return serializeHeaderFooter(footerSerializer);
- }
-
- private byte[] serializeHeaderFooter(final Serializer serializer) {
- if (serializer == null) {
- return null;
- }
- final LoggerConfig rootLogger = config.getRootLogger();
- // Using "" for the FQCN, does it matter?
- final LogEvent logEvent = rootLogger.getLogEventFactory().createEvent(rootLogger.getName(), null, Strings.EMPTY,
- rootLogger.getLevel(), null, null, null);
- return StringEncoder.toBytes(serializer.toSerializable(logEvent), getCharset());
- }
-
/**
* Gets the conversion pattern.
*
@@ -279,11 +246,6 @@ public final class PatternLayout extends AbstractStringLayout {
.build();
}
- public interface Serializer {
-
- String toSerializable(final LogEvent event);
- }
-
private static class PatternSerializer implements Serializer {
private final PatternFormatter[] formatters;
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/75d33d96/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/SerializedLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/SerializedLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/SerializedLayout.java
index f60c1b2..6d2349d 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/SerializedLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/SerializedLayout.java
@@ -48,7 +48,7 @@ public final class SerializedLayout extends AbstractLayout<LogEvent> {
}
private SerializedLayout() {
- super(null, null);
+ super(null, null, null);
}
/**
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/75d33d96/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/XmlLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/XmlLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/XmlLayout.java
index 5badaca..8e01bd3 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/XmlLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/XmlLayout.java
@@ -197,7 +197,7 @@ public final class XmlLayout extends AbstractJacksonLayout {
private static final String ROOT_TAG = "Events";
protected XmlLayout(final boolean locationInfo, final boolean properties, final boolean complete, final boolean compact, final Charset charset) {
- super(new JacksonFactory.XML().newWriter(locationInfo, properties, compact), charset, compact, complete, false);
+ super(null, new JacksonFactory.XML().newWriter(locationInfo, properties, compact), charset, compact, complete, false, null, null);
}
/**
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/75d33d96/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SmtpManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SmtpManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SmtpManager.java
index 67f0932..2f15042 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SmtpManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SmtpManager.java
@@ -42,10 +42,8 @@ import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractManager;
import org.apache.logging.log4j.core.appender.ManagerFactory;
import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.DefaultConfiguration;
-import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
+import org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer;
import org.apache.logging.log4j.core.layout.PatternLayout;
-import org.apache.logging.log4j.core.layout.PatternLayout.Serializer;
import org.apache.logging.log4j.core.util.CyclicBuffer;
import org.apache.logging.log4j.core.util.NameUtil;
import org.apache.logging.log4j.core.util.NetUtils;
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/75d33d96/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/CsvLogEventLayoutTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/CsvLogEventLayoutTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/CsvLogEventLayoutTest.java
index f0f6d95..688cb42 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/CsvLogEventLayoutTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/CsvLogEventLayoutTest.java
@@ -64,12 +64,21 @@ public class CsvLogEventLayoutTest {
@Test
public void testCustomCharset() {
- final AbstractCsvLayout layout = CsvLogEventLayout.createLayout("Excel", null, null, null, null, null, null,
- StandardCharsets.UTF_16, null, null);
+ final AbstractCsvLayout layout = CsvLogEventLayout.createLayout(null, "Excel", null, null, null, null, null,
+ null, StandardCharsets.UTF_16, null, null);
assertEquals("text/csv; charset=UTF-16", layout.getContentType());
}
@Test
+ public void testHeaderFooter() {
+ final String header = "# Header";
+ final String footer = "# Footer ";
+ final AbstractCsvLayout layout = CsvLogEventLayout.createLayout(ctx.getConfiguration(), "Excel", null, null,
+ null, null, null, null, null, header, footer);
+ testLayout(CSVFormat.DEFAULT, layout, header, footer);
+ }
+
+ @Test
public void testDefaultCharset() {
final AbstractCsvLayout layout = CsvLogEventLayout.createDefaultLayout();
assertEquals(StandardCharsets.UTF_8, layout.getCharset());
@@ -82,7 +91,10 @@ public class CsvLogEventLayoutTest {
}
private void testLayout(final CSVFormat format) {
- final AbstractCsvLayout layout = CsvLogEventLayout.createLayout(format);
+ testLayout(format, CsvLogEventLayout.createLayout(format), null, null);
+ }
+
+ private void testLayout(final CSVFormat format, final AbstractCsvLayout layout, String header, String footer) {
final Map<String, Appender> appenders = root.getAppenders();
for (final Appender appender : appenders.values()) {
root.removeAppender(appender);
@@ -100,13 +112,35 @@ public class CsvLogEventLayoutTest {
appender.stop();
final List<String> list = appender.getMessages();
- final String event0 = list.get(0);
+ final boolean hasHeaderSerializer = layout.getHeaderSerializer() != null;
+ final boolean hasFooterSerializer = layout.getFooterSerializer() != null;
+ final int headerOffset = hasHeaderSerializer ? 1 : 0;
+ final String event0 = list.get(0 + headerOffset);
+ final String event1 = list.get(1 + headerOffset);
final char del = format.getDelimiter();
Assert.assertTrue(event0, event0.contains(del + "DEBUG" + del));
final String quote = del == ',' ? "\"" : "";
Assert.assertTrue(event0, event0.contains(del + quote + "one=1, two=2, three=3" + quote + del));
- final String event1 = list.get(1);
Assert.assertTrue(event1, event1.contains(del + "INFO" + del));
+
+ if (hasHeaderSerializer && header == null) {
+ Assert.fail();
+ }
+ if (!hasHeaderSerializer && header != null) {
+ Assert.fail();
+ }
+ if (hasFooterSerializer && footer == null) {
+ Assert.fail();
+ }
+ if (!hasFooterSerializer && footer != null) {
+ Assert.fail();
+ }
+ if (hasHeaderSerializer) {
+ Assert.assertEquals(list.toString(), header, list.get(0));
+ }
+ if (hasFooterSerializer) {
+ Assert.assertEquals(list.toString(), footer, list.get(list.size() - 1));
+ }
}
@Test
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/75d33d96/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 0bbe3c6..27a7318 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
@@ -65,8 +65,8 @@ public class CsvParameterLayoutTest {
@Test
public void testCustomCharset() {
- final AbstractCsvLayout layout = CsvParameterLayout.createLayout("Excel", null, null, null, null, null, null,
- StandardCharsets.UTF_16, null, null);
+ final AbstractCsvLayout layout = CsvParameterLayout.createLayout(null, "Excel", null, null, null, null, null,
+ null, StandardCharsets.UTF_16, null, null);
assertEquals("text/csv; charset=UTF-16", layout.getContentType());
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/75d33d96/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/JsonLayoutTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/JsonLayoutTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/JsonLayoutTest.java
index 87b075c..22b017f 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/JsonLayoutTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/JsonLayoutTest.java
@@ -30,6 +30,7 @@ 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.Configuration;
import org.apache.logging.log4j.core.config.ConfigurationFactory;
import org.apache.logging.log4j.core.impl.Log4jLogEvent;
import org.apache.logging.log4j.core.jackson.Log4jJsonObjectMapper;
@@ -105,8 +106,8 @@ public class JsonLayoutTest {
private void testAllFeatures(final boolean includeSource, final boolean compact, final boolean eventEol, final boolean includeContext)
throws Exception {
final Log4jLogEvent expected = LogEventFixtures.createLogEvent();
- final AbstractJacksonLayout layout = JsonLayout.createLayout(includeSource,
- includeContext, false, compact, eventEol, StandardCharsets.UTF_8);
+ final AbstractJacksonLayout layout = JsonLayout.createLayout(null, includeSource,
+ includeContext, false, compact, eventEol, null, null, StandardCharsets.UTF_8);
final String str = layout.toSerializable(expected);
// System.out.println(str);
final String propSep = this.toPropertySeparator(compact);
@@ -176,8 +177,9 @@ public class JsonLayoutTest {
for (final Appender appender : appenders.values()) {
this.rootLogger.removeAppender(appender);
}
+ final Configuration configuration = rootLogger.getContext().getConfiguration();
// set up appender
- final AbstractJacksonLayout layout = JsonLayout.createLayout(true, true, true, false, false, null);
+ final AbstractJacksonLayout layout = JsonLayout.createLayout(configuration, true, true, true, false, false, null, null, null);
final ListAppender appender = new ListAppender("List", null, layout, true, false);
appender.start();
@@ -211,8 +213,10 @@ public class JsonLayoutTest {
for (final Appender appender : appenders.values()) {
this.rootLogger.removeAppender(appender);
}
+ final Configuration configuration = rootLogger.getContext().getConfiguration();
// set up appender
- final AbstractJacksonLayout layout = JsonLayout.createLayout(true, true, true, false, false, null);
+ // Use [[ and ]] to test header and footer (instead of [ and ])
+ final AbstractJacksonLayout layout = JsonLayout.createLayout(configuration, true, true, true, false, false, "[[", "]]", null);
final ListAppender appender = new ListAppender("List", null, layout, true, false);
appender.start();
@@ -239,7 +243,7 @@ public class JsonLayoutTest {
final List<String> list = appender.getMessages();
- this.checkAt("[", 0, list);
+ this.checkAt("[[", 0, list);
this.checkAt("{", 1, list);
this.checkContains("\"loggerFqcn\" : \"" + AbstractLogger.class.getName() + "\",", list);
this.checkContains("\"level\" : \"DEBUG\",", list);
@@ -251,7 +255,8 @@ public class JsonLayoutTest {
@Test
public void testLayoutLoggerName() throws Exception {
- final AbstractJacksonLayout layout = JsonLayout.createLayout(false, false, false, true, false, StandardCharsets.UTF_8);
+ final AbstractJacksonLayout layout = JsonLayout.createLayout(null, false, false, false, true, false, null, null,
+ StandardCharsets.UTF_8);
final Log4jLogEvent expected = Log4jLogEvent.newBuilder() //
.setLoggerName("a.B") //
.setLoggerFqcn("f.q.c.n") //
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/75d33d96/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/AbstractSocketServerTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/AbstractSocketServerTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/AbstractSocketServerTest.java
index 06adc8a..ee5c2de 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/AbstractSocketServerTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/AbstractSocketServerTest.java
@@ -78,7 +78,7 @@ public abstract class AbstractSocketServerTest {
}
protected Layout<String> createJsonLayout() {
- return JsonLayout.createLayout(true, true, false, false, false, null);
+ return JsonLayout.createLayout(null, true, true, false, false, false, null, null, null);
}
protected abstract Layout<? extends Serializable> createLayout();
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/75d33d96/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 3182a0c..d6de059 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -31,6 +31,12 @@
<action issue="LOG4J2-1237" dev="ggregory" type="add" due-to="Mike Calmus, Gary Gregory">
Make PatternLayout header and footer accept a pattern.
</action>
+ <action issue="LOG4J2-1244" dev="ggregory" type="add" due-to="Anshu Garg, Remko Popma, Gary Gregory">
+ Make header and footer values customizable in JSONLayout.
+ </action>
+ <action issue="LOG4J2-1245" dev="ggregory" type="add">
+ Make CSV Layout header and footers accept patterns.
+ </action>
<action issue="LOG4J2-1192" dev="ggregory" type="add" due-to="Jörg Bretschneider, Gary Gregory">
Dynamic Subject for SMTP Appender.
</action>
[48/50] logging-log4j2 git commit: [LOG4J2-1232] Incorrect log
rotation in last week of year.
Posted by mi...@apache.org.
[LOG4J2-1232] Incorrect log rotation in last week of year.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/9d1ffa7e
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/9d1ffa7e
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/9d1ffa7e
Branch: refs/heads/LOG4J-1181
Commit: 9d1ffa7e4683b16c653a6fe3f2f3093662526cb2
Parents: 6971f58
Author: ggregory <gg...@apache.org>
Authored: Mon Jan 11 10:36:11 2016 -0800
Committer: ggregory <gg...@apache.org>
Committed: Mon Jan 11 10:36:11 2016 -0800
----------------------------------------------------------------------
.../log4j/core/appender/rolling/PatternProcessor.java | 6 ++++++
.../log4j/core/appender/rolling/PatternProcessorTest.java | 8 +++++---
src/changes/changes.xml | 3 +++
3 files changed, 14 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9d1ffa7e/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java
index fbc74b4..af5bcdb 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java
@@ -88,6 +88,10 @@ public class PatternProcessor {
* @return the next potential rollover time and the timestamp for the target file.
*/
public long getNextTime(final long currentMillis, final int increment, final boolean modulus) {
+ //
+ // https://issues.apache.org/jira/browse/LOG4J2-1232
+ // Call setMinimalDaysInFirstWeek(7);
+ //
prevFileTime = nextFileTime;
long nextTime;
@@ -97,6 +101,8 @@ public class PatternProcessor {
final Calendar currentCal = Calendar.getInstance();
currentCal.setTimeInMillis(currentMillis);
final Calendar cal = Calendar.getInstance();
+ currentCal.setMinimalDaysInFirstWeek(7);
+ cal.setMinimalDaysInFirstWeek(7);
cal.set(currentCal.get(Calendar.YEAR), 0, 1, 0, 0, 0);
cal.set(Calendar.MILLISECOND, 0);
if (frequency == RolloverFrequency.ANNUALLY) {
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9d1ffa7e/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessorTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessorTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessorTest.java
index 58b27d9..3b9e22a 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessorTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessorTest.java
@@ -236,8 +236,10 @@ public class PatternProcessorTest {
}
}
+ /**
+ * Tests https://issues.apache.org/jira/browse/LOG4J2-1232
+ */
@Test
- @Ignore("https://issues.apache.org/jira/browse/LOG4J2-1232")
public void testGetNextTimeWeeklyReturnsFirstWeekInYear_US() {
final Locale old = Locale.getDefault();
Locale.setDefault(Locale.US); // force 1st day of the week to be Sunday
@@ -247,9 +249,9 @@ public class PatternProcessorTest {
initial.set(2015, Calendar.DECEMBER, 28, 00, 00, 00); // Monday, December 28, 2015
final long actual = pp.getNextTime(initial.getTimeInMillis(), 1, false);
- // expect Monday January 4, 2016
+ // expect Sunday January 3, 2016
final Calendar expected = Calendar.getInstance();
- expected.set(2016, Calendar.JANUARY, 4, 00, 00, 00);
+ expected.set(2016, Calendar.JANUARY, 3, 00, 00, 00);
expected.set(Calendar.MILLISECOND, 0);
assertEquals(format(expected.getTimeInMillis()), format(actual));
} finally {
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9d1ffa7e/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 17c81f6..63fb8c5 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -40,6 +40,9 @@
<action issue="LOG4J2-1192" dev="ggregory" type="add" due-to="Jörg Bretschneider, Gary Gregory">
Dynamic Subject for SMTP Appender.
</action>
+ <action issue="LOG4J2-1232" dev="ggregory" type="fix" due-to="Nikolai">
+ Incorrect log rotation in last week of year.
+ </action>
<action issue="LOG4J2-1248" dev="rpopma" type="fix">
Fixed broken nanotime in pattern layout.
</action>
[38/50] logging-log4j2 git commit: [LOG4J2-1237] Make PatternLayout
header and footer accept a pattern. Move code in try-catch block.
Posted by mi...@apache.org.
[LOG4J2-1237] Make PatternLayout header and footer accept a pattern.
Move code in try-catch block.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/d5aff9e8
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/d5aff9e8
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/d5aff9e8
Branch: refs/heads/LOG4J-1181
Commit: d5aff9e863bb113c9cf1c5ff90ceb0e60aec7f71
Parents: dd079d1
Author: ggregory <gg...@apache.org>
Authored: Mon Jan 4 14:00:57 2016 -0800
Committer: ggregory <gg...@apache.org>
Committed: Mon Jan 4 14:00:57 2016 -0800
----------------------------------------------------------------------
.../java/org/apache/logging/log4j/core/layout/PatternLayout.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d5aff9e8/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java
index 63c44fd..4f9244d 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java
@@ -134,8 +134,8 @@ public final class PatternLayout extends AbstractStringLayout {
return null;
}
if (patternSelector == null) {
- final PatternParser parser = createPatternParser(configuration);
try {
+ final PatternParser parser = createPatternParser(configuration);
final List<PatternFormatter> list = parser.parse(pattern == null ? defaultPattern : pattern,
alwaysWriteExceptions, noConsoleNoAnsi);
final PatternFormatter[] formatters = list.toArray(new PatternFormatter[0]);
[28/50] logging-log4j2 git commit: [LOG4J2-1232] Incorrect log
rotation in last week of year. Inline lvar.
Posted by mi...@apache.org.
[LOG4J2-1232] Incorrect log rotation in last week of year. Inline lvar.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/15b087cc
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/15b087cc
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/15b087cc
Branch: refs/heads/LOG4J-1181
Commit: 15b087cc39c3ba0e6bc6707823ea918d1ad6bc2d
Parents: 5644b13
Author: ggregory <gg...@apache.org>
Authored: Thu Dec 31 18:52:04 2015 -0800
Committer: ggregory <gg...@apache.org>
Committed: Thu Dec 31 18:52:04 2015 -0800
----------------------------------------------------------------------
.../logging/log4j/core/appender/rolling/PatternProcessorTest.java | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/15b087cc/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessorTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessorTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessorTest.java
index f366877..58b27d9 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessorTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessorTest.java
@@ -33,8 +33,7 @@ import static org.junit.Assert.*;
public class PatternProcessorTest {
private String format(final long time) {
- final String actualStr = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS").format(new Date(time));
- return actualStr;
+ return new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS").format(new Date(time));
}
@Test
[14/50] logging-log4j2 git commit: Fix Javadoc.
Posted by mi...@apache.org.
Fix Javadoc.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/aa2c0cdb
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/aa2c0cdb
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/aa2c0cdb
Branch: refs/heads/LOG4J-1181
Commit: aa2c0cdbd63d4866c86226be1c752e323e8dc3a1
Parents: 7da92de
Author: ggregory <gg...@apache.org>
Authored: Wed Dec 30 12:57:48 2015 -0800
Committer: ggregory <gg...@apache.org>
Committed: Wed Dec 30 12:57:48 2015 -0800
----------------------------------------------------------------------
.../main/java/org/apache/logging/log4j/core/layout/JsonLayout.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/aa2c0cdb/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java
index 5f3969c..0f1b618 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java
@@ -790,7 +790,7 @@ import org.apache.logging.log4j.core.config.plugins.PluginFactory;
* </p>
* <h3>Pretty vs. compact XML</h3>
* <p>
- * By default, the JSON layout is not compact (a.k.a. not "pretty") with {@code compact="false"}, which means the
+ * By default, the JSON layout is not compact (a.k.a. "pretty") with {@code compact="false"}, which means the
* appender uses end-of-line characters and indents lines to format the text. If {@code compact="true"}, then no
* end-of-line or indentation is used. Message content may contain, of course, escaped end-of-lines.
* </p>
[02/50] logging-log4j2 git commit: LOG4J2-1080 documentation
Posted by mi...@apache.org.
LOG4J2-1080 documentation
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/c484ec61
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/c484ec61
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/c484ec61
Branch: refs/heads/LOG4J-1181
Commit: c484ec61f5db1eebb7bf818448a8af41342bab08
Parents: d97cd82
Author: rpopma <rp...@apache.org>
Authored: Wed Dec 23 22:15:37 2015 +0900
Committer: rpopma <rp...@apache.org>
Committed: Wed Dec 23 22:15:37 2015 +0900
----------------------------------------------------------------------
src/site/xdoc/manual/appenders.xml | 83 ++++++++++++++------------
src/site/xdoc/manual/async.xml | 16 ++++-
src/site/xdoc/manual/configuration.xml.vm | 39 ++++++++++--
3 files changed, 95 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c484ec61/src/site/xdoc/manual/appenders.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/manual/appenders.xml b/src/site/xdoc/manual/appenders.xml
index 97679dd..69ed1a0 100644
--- a/src/site/xdoc/manual/appenders.xml
+++ b/src/site/xdoc/manual/appenders.xml
@@ -120,6 +120,13 @@
</tr>
</table>
<p>
+ There are also a few system properties that can be used to maintain application throughput even when
+ the underlying appender cannot keep up with the logging rate and the queue is filling up.
+ See the details for system properties
+ <a href="configuration.html#AsyncEventRouter"><tt>log4j2.AsyncEventRouter</tt>,
+ <tt>log4j2.DiscardThreshold</tt> and <tt>log4j2.DiscardQueueRatio</tt></a>.
+ </p>
+ <p>
A typical AsyncAppender configuration might look like:
</p>
@@ -1256,8 +1263,8 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
<td>layout</td>
<td>Layout</td>
<td>
- The Layout to use to format the LogEvent. If you do not specify a layout, the appender will send the
- <a class="javadoc" href="http://logging.apache.org/log4j/2.x/log4j-api/apidocs/org/apache/logging/log4j/message/Message.html#getFormattedMessage())">formatted message</a>
+ The Layout to use to format the LogEvent. If you do not specify a layout, the appender will send the
+ <a class="javadoc" href="http://logging.apache.org/log4j/2.x/log4j-api/apidocs/org/apache/logging/log4j/message/Message.html#getFormattedMessage())">formatted message</a>
to Kafka as a UTF-8 encoded string.
</td>
</tr>
@@ -2004,7 +2011,7 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
<p>
You can use this policy to make loggers in third party code less chatty by changing event levels.
The LoggerNameLevelRewritePolicy will rewrite log event levels for a given logger name prefix.
- You configure a LoggerNameLevelRewritePolicy with a logger name prefix and a pairs of levels,
+ You configure a LoggerNameLevelRewritePolicy with a logger name prefix and a pairs of levels,
where a pair defines a source level and a target level.
</p>
<table>
@@ -2025,8 +2032,8 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
</tr>
</table>
<p>
- The following configuration shows a RewriteAppender configured to map level INFO to DEBUG and level
- WARN to INFO for all loggers that start with <code>com.foo.bar</code>.
+ The following configuration shows a RewriteAppender configured to map level INFO to DEBUG and level
+ WARN to INFO for all loggers that start with <code>com.foo.bar</code>.
</p>
<pre class="prettyprint linenums"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" name="MyApp">
@@ -2263,11 +2270,11 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
is present it will be replaced with the current date and time values. If the pattern contains an integer
it will be incremented on each rollover. If the pattern contains both a date/time and integer
in the pattern the integer will be incremented until the result of the date/time pattern changes. If
- the file pattern ends with ".gz", ".zip", ".bz2", ".deflate", ".pack200", or ".xz" the resulting archive
- will be compressed using the compression scheme that matches the suffix. The formats bzip2, Deflate,
+ the file pattern ends with ".gz", ".zip", ".bz2", ".deflate", ".pack200", or ".xz" the resulting archive
+ will be compressed using the compression scheme that matches the suffix. The formats bzip2, Deflate,
Pack200 and XZ require <a href="http://commons.apache.org/proper/commons-compress/">Apache Commons Compress</a>.
- In addition, XZ requires <a href="http://tukaani.org/xz/java.html">XZ for Java</a>.
- The pattern may also contain lookup references that can be resolved at runtime such as is shown in the example
+ In addition, XZ requires <a href="http://tukaani.org/xz/java.html">XZ for Java</a>.
+ The pattern may also contain lookup references that can be resolved at runtime such as is shown in the example
below.
</p>
<p>The default rollover strategy supports two variations for incrementing the counter. The first is
@@ -2526,7 +2533,7 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
<tr>
<td>pathSorter</td>
<td>PathSorter</td>
- <td>A plugin implementing the
+ <td>A plugin implementing the
<a href="../log4j-core/apidocs/org/apache/logging/log4j/core/appender/rolling/action/PathSorter.html">PathSorter</a>
interface to sort the files before selecting the files to delete. The default is to sort most recently
modified files first.</td>
@@ -2542,8 +2549,8 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
If conditions are not nested they may be evaluated in any order.
</p>
<p>
- Conditions can also be combined with the logical operators AND, OR and NOT by using the
- <tt>IfAll</tt>, <tt>IfAny</tt> and <tt>IfNot</tt> composite conditions.
+ Conditions can also be combined with the logical operators AND, OR and NOT by using the
+ <tt>IfAll</tt>, <tt>IfAny</tt> and <tt>IfNot</tt> composite conditions.
</p>
<p>Users can create custom conditions or use the built-in conditions:</p>
<ul>
@@ -2568,7 +2575,7 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
<td>ScriptCondition</td>
<td><p><em>Required if no PathConditions are specified.</em> A ScriptCondition element specifying a script.</p>
<p>
- The ScriptCondition should contain a <a href="#ScriptCondition">Script,
+ The ScriptCondition should contain a <a href="#ScriptCondition">Script,
ScriptRef or ScriptFile</a> element that specifies the logic to be executed.
(See also the <a href="filters.html#Script">ScriptFilter</a> documentation for more examples of
configuring ScriptFiles and ScriptRefs.)
@@ -2590,15 +2597,15 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
<tr>
<td>glob</td>
<td>String</td>
- <td><em>Required if regex not specified.</em>
- Matches the relative path (relative to the base path) using a limited pattern language that resembles regular expressions but with a
+ <td><em>Required if regex not specified.</em>
+ Matches the relative path (relative to the base path) using a limited pattern language that resembles regular expressions but with a
<a href="https://docs.oracle.com/javase/7/docs/api/java/nio/file/FileSystem.html#getPathMatcher(java.lang.String)">simpler syntax</a>.
</td>
</tr>
<tr>
<td>regex</td>
<td>String</td>
- <td><em>Required if glob not specified.</em>
+ <td><em>Required if glob not specified.</em>
Matches the relative path (relative to the base path) using a regular expression as defined by the
<a href="https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html">Pattern</a> class.
</td>
@@ -2608,7 +2615,7 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
<td>PathCondition[]</td>
<td>An optional set of nested <a href="#DeletePathCondition">PathConditions</a>. If any nested conditions
exist they all need to accept the file before it is deleted. Nested conditions are only evaluated if the
- outer condition accepts a file (if the path name matches).
+ outer condition accepts a file (if the path name matches).
</td>
</tr>
</table>
@@ -2623,7 +2630,7 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
<tr>
<td>age</td>
<td>String</td>
- <td><em>Required.</em>
+ <td><em>Required.</em>
Specifies a <a href="../log4j-core/apidocs/org/apache/logging/log4j/core/appender/rolling/action/Duration.html#parse(CharSequence)">duration</a>.
The condition accepts files that are as old or older than the specified duration.
</td>
@@ -2633,7 +2640,7 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
<td>PathCondition[]</td>
<td>An optional set of nested <a href="#DeletePathCondition">PathConditions</a>. If any nested conditions
exist they all need to accept the file before it is deleted. Nested conditions are only evaluated if the
- outer condition accepts a file (if the file is old enough).
+ outer condition accepts a file (if the file is old enough).
</td>
</tr>
</table>
@@ -2648,7 +2655,7 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
<tr>
<td>exceeds</td>
<td>int</td>
- <td><em>Required.</em>
+ <td><em>Required.</em>
The threshold count from which files will be deleted.
</td>
</tr>
@@ -2657,7 +2664,7 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
<td>PathCondition[]</td>
<td>An optional set of nested <a href="#DeletePathCondition">PathConditions</a>. If any nested conditions
exist they all need to accept the file before it is deleted. Nested conditions are only evaluated if the
- outer condition accepts a file (if the threshold count has been exceeded).
+ outer condition accepts a file (if the threshold count has been exceeded).
</td>
</tr>
</table>
@@ -2672,7 +2679,7 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
<tr>
<td>exceeds</td>
<td>String</td>
- <td><em>Required.</em>
+ <td><em>Required.</em>
The threshold accumulated file size from which files will be deleted.
The size can be specified in bytes, with the suffix KB, MB or GB, for example <tt>20MB</tt>.
</td>
@@ -2682,7 +2689,7 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
<td>PathCondition[]</td>
<td>An optional set of nested <a href="#DeletePathCondition">PathConditions</a>. If any nested conditions
exist they all need to accept the file before it is deleted. Nested conditions are only evaluated if the
- outer condition accepts a file (if the threshold accumulated file size has been exceeded).
+ outer condition accepts a file (if the threshold accumulated file size has been exceeded).
</td>
</tr>
</table>
@@ -2723,9 +2730,9 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
triggering policies, will create up to 100 archives on the same day (1-100) that are stored in a directory
based on the current year and month, and will compress each
archive using gzip and will roll every hour.
-
- During every rollover, this configuration will delete files that match "*/app-*.log.gz"
- and are 30 days old or older,
+
+ During every rollover, this configuration will delete files that match "*/app-*.log.gz"
+ and are 30 days old or older,
but keep the most recent 100 GB or the most recent 10 files, whichever comes first.
</p>
@@ -2848,16 +2855,16 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
<ScriptCondition>
<Script name="superstitious" language="groovy"><![CDATA[
import java.nio.file.*;
-
- def result = [];
+
+ def result = [];
def pattern = ~/\d*\/app-(\d*)\.log\.gz/;
-
+
pathList.each { pathWithAttributes ->
def relative = basePath.relativize pathWithAttributes.path
statusLogger.trace 'SCRIPT: relative path=' + relative + " (base=$basePath)";
-
+
// remove files dated Friday the 13th
-
+
def matcher = pattern.matcher(relative.toString());
if (matcher.find()) {
def dateString = matcher.group(1);
@@ -3727,8 +3734,8 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
<a name="JeroMQAppender"/>
<subsection name="ZeroMQ/JeroMQ Appender">
<p>
- The ZeroMQ appender uses the <a href="https://github.com/zeromq/jeromq">JeroMQ</a> library to send log
- events to one or more ZeroMQ endpoints.
+ The ZeroMQ appender uses the <a href="https://github.com/zeromq/jeromq">JeroMQ</a> library to send log
+ events to one or more ZeroMQ endpoints.
</p>
<p>
This is a simple JeroMQ configuration:
@@ -3736,7 +3743,7 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
<pre class="prettyprint linenums"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<Configuration name="JeroMQAppenderTest" status="TRACE">
<Appenders>
- <JeroMQ name="JeroMQAppender">
+ <JeroMQ name="JeroMQAppender">
<Property name="endpoint">tcp://*:5556</Property>
<Property name="endpoint">ipc://info-topic</Property>
</JeroMQ>
@@ -3746,7 +3753,7 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
<AppenderRef ref="JeroMQAppender"/>
</Root>
</Loggers>
-</Configuration>]]></pre>
+</Configuration>]]></pre>
<p>
The table below describes all options. Please consult the JeroMQ and ZeroMQ documentation for details.
</p>
@@ -3765,8 +3772,8 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
<tr>
<td>Layout</td>
<td>layout</td>
- <td>The Layout of the Appender. If you do not specify a layout, the appender uses the default
- pattern appender returned by
+ <td>The Layout of the Appender. If you do not specify a layout, the appender uses the default
+ pattern appender returned by
<a href="https://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/layout/PatternLayout.html#createDefaultLayout()">PatternLayout.createDefaultLayout()</a>.</td>
</tr>
<tr>
@@ -3884,7 +3891,7 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
<td>boolean</td>
<td>The ZMQ_XPUB_VERBOSE option. Defaults to false.</td>
</tr>
- </table>
+ </table>
</subsection>
</section>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c484ec61/src/site/xdoc/manual/async.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/manual/async.xml b/src/site/xdoc/manual/async.xml
index eb9e16b..0f6a754 100644
--- a/src/site/xdoc/manual/async.xml
+++ b/src/site/xdoc/manual/async.xml
@@ -265,12 +265,19 @@
of applications.
</p>
<p>
- You can also specify a fully qualified class name of a custom class that implements the
+ You can also specify the fully qualified class name of a custom class that implements the
<tt>Clock</tt> interface.
</p>
</td>
</tr>
</table>
+ <p>
+ There are also a few system properties that can be used to maintain application throughput even when
+ the underlying appender cannot keep up with the logging rate and the queue is filling up.
+ See the details for system properties
+ <a href="configuration.html#AsyncEventRouter"><tt>log4j2.AsyncEventRouter</tt>,
+ <tt>log4j2.DiscardThreshold</tt> and <tt>log4j2.DiscardQueueRatio</tt></a>.
+ </p>
</subsection>
<a name="MixedSync-Async" />
<subsection name="Mixing Synchronous and Asynchronous Loggers">
@@ -379,6 +386,13 @@
</td>
</tr>
</table>
+ <p>
+ There are also a few system properties that can be used to maintain application throughput even when
+ the underlying appender cannot keep up with the logging rate and the queue is filling up.
+ See the details for system properties
+ <a href="configuration.html#AsyncEventRouter"><tt>log4j2.AsyncEventRouter</tt>,
+ <tt>log4j2.DiscardThreshold</tt> and <tt>log4j2.DiscardQueueRatio</tt></a>.
+ </p>
</subsection>
<a name="Location" />
<subsection name="Location, location, location...">
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c484ec61/src/site/xdoc/manual/configuration.xml.vm
----------------------------------------------------------------------
diff --git a/src/site/xdoc/manual/configuration.xml.vm b/src/site/xdoc/manual/configuration.xml.vm
index a417151..93b4663 100644
--- a/src/site/xdoc/manual/configuration.xml.vm
+++ b/src/site/xdoc/manual/configuration.xml.vm
@@ -71,9 +71,9 @@
<li>Log4j will inspect the <code>"log4j.configurationFile"</code> system property and, if set, will attempt to
load the configuration using the <code>ConfigurationFactory</code> that matches the file
extension.</li>
- <li>If no system property is set the properties ConfigurationFactory will look for
+ <li>If no system property is set the properties ConfigurationFactory will look for
<code>log4j2-test.properties</code> in the classpath.</li>
- <li>If no such file is found the YAML ConfigurationFactory will look for
+ <li>If no such file is found the YAML ConfigurationFactory will look for
<code>log4j2-test.yaml</code> or <code>log4j2-test.yml</code> in the classpath.</li>
<li>If no such file is found the JSON ConfigurationFactory will look for
<code>log4j2-test.json</code> or <code>log4j2-test.jsn</code> in the classpath.</li>
@@ -280,7 +280,7 @@ public class Bar {
<subsection name="Automatic Reconfiguration">
<p>
When configured from a File, Log4j has the ability to automatically detect changes to the configuration
- file and reconfigure itself. If the <code>monitorInterval</code> attribute is specified on the configuration
+ file and reconfigure itself. If the <code>monitorInterval</code> attribute is specified on the configuration
element and is set to a non-zero value then the file will be checked the next time a log event is evaluated
and/or logged and the monitorInterval has elapsed since the last check. The example below shows how
to configure the attribute so that the configuration file will be checked for changes only after at
@@ -948,7 +948,7 @@ rootLogger.appenderRef.stdout.ref = STDOUT
<p>
While this is useful, there are many more places properties can originate from. To accommodate this,
Log4j also supports the syntax <code>${dollar}{prefix:name}</code> where the prefix identifies tells Log4j
- that variable name should be evaluated in a specific context.
+ that variable name should be evaluated in a specific context.
See the <a href="lookups.html">Lookups</a> manual page for more details.
The contexts that are built in to Logj4 are:
</p>
@@ -1872,6 +1872,37 @@ public class AwesomeTest {
the value at the time of the call to the logger is the value that is logged.
</td>
</tr>
+ <tr>
+ <td><a name="AsyncEventRouter"/>log4j2.AsyncEventRouter</td>
+ <td> </td>
+ <td>
+ <p>Used by Async Loggers and the AsyncAppender to maintain application throughput even when
+ the underlying appender cannot keep up with the logging rate and the queue is filling up.</p>
+ <p>If no value is specified (the default) events are never discarded. If the queue is full, the
+ logger call blocks until the event can be added to the queue.</p>
+ <p>Specify <tt>Discard</tt> to drop events whose level is equal or less than the threshold level
+ (INFO by default) when the queue has been filled to the discard ratio (0.8 by default).</p>
+ <p>It is also possible to specify the fully qualified class name of a custom class that implements the
+ <tt>org.apache.logging.log4j.core.async.AsyncEventRouter</tt> interface.</p>
+ </td>
+ </tr>
+ <tr>
+ <td>log4j2.DiscardThreshold</td>
+ <td>INFO</td>
+ <td>Used by the DiscardingAsyncEventRouter to determine which events to drop when the queue
+ becomes too full. By default, <tt>INFO</tt>, <tt>DEBUG</tt> and <tt>TRACE</tt> level
+ events are discarded when the queue has been filled up to or beyond the discard ratio.
+ This property only has effect if <tt>Discard</tt> is specified as the
+ <tt>log4j2.AsyncEventRouter</tt>.</td>
+ </tr>
+ <tr>
+ <td>log4j2.DiscardQueueRatio</td>
+ <td>0.8</td>
+ <td>Used by the DiscardingAsyncEventRouter to determine when the queue is becoming too full.
+ By default, events may be discarded when the queue is 80% full or more.
+ This property only has effect if <tt>Discard</tt> is specified as the
+ <tt>log4j2.AsyncEventRouter</tt>.</td>
+ </tr>
</table>
</subsection>
[36/50] logging-log4j2 git commit: findbugs.plugin.version 3.0.2 ->
3.0.3.
Posted by mi...@apache.org.
findbugs.plugin.version 3.0.2 -> 3.0.3.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/235871e4
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/235871e4
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/235871e4
Branch: refs/heads/LOG4J-1181
Commit: 235871e4331936931ddc54fff3fb93ebceefb4de
Parents: 4156fbc
Author: ggregory <gg...@apache.org>
Authored: Sun Jan 3 22:40:11 2016 -0800
Committer: ggregory <gg...@apache.org>
Committed: Sun Jan 3 22:40:11 2016 -0800
----------------------------------------------------------------------
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/235871e4/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index ef760ba..890c2e3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -196,7 +196,7 @@
<disruptorVersion>3.3.2</disruptorVersion>
<compiler.plugin.version>3.3</compiler.plugin.version>
<pmd.plugin.version>3.5</pmd.plugin.version>
- <findbugs.plugin.version>3.0.2</findbugs.plugin.version>
+ <findbugs.plugin.version>3.0.3</findbugs.plugin.version>
<changes.plugin.version>2.11</changes.plugin.version>
<javadoc.plugin.version>2.10.3</javadoc.plugin.version>
<!-- surefire.plugin.version 2.18 yields http://jira.codehaus.org/browse/SUREFIRE-1121, which is fixed in 2.18.1 -->
[39/50] logging-log4j2 git commit: Formatting.
Posted by mi...@apache.org.
Formatting.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/09c1fe25
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/09c1fe25
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/09c1fe25
Branch: refs/heads/LOG4J-1181
Commit: 09c1fe250516cebcc78847be39f4e02e2d127c66
Parents: d5aff9e
Author: ggregory <gg...@apache.org>
Authored: Mon Jan 4 14:47:35 2016 -0800
Committer: ggregory <gg...@apache.org>
Committed: Mon Jan 4 14:47:35 2016 -0800
----------------------------------------------------------------------
.../org/apache/logging/log4j/core/appender/ConsoleAppender.java | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/09c1fe25/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java
index 10abd72..0925e10 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java
@@ -121,12 +121,15 @@ public final class ConsoleAppender extends AbstractOutputStreamAppender<OutputSt
* @return The ConsoleAppender.
*/
@PluginFactory
- public static ConsoleAppender createAppender(@PluginElement("Layout") Layout<? extends Serializable> layout,
+ public static ConsoleAppender createAppender(
+ // @formatter:off
+ @PluginElement("Layout") Layout<? extends Serializable> layout,
@PluginElement("Filter") final Filter filter,
@PluginAttribute(value = "target") Target target,
@PluginAttribute("name") final String name,
@PluginAttribute(value = "follow", defaultBoolean = false) final boolean follow,
@PluginAttribute(value = "ignoreExceptions", defaultBoolean = true) final boolean ignoreExceptions) {
+ // @formatter:on
if (name == null) {
LOGGER.error("No name provided for ConsoleAppender");
return null;
[10/50] logging-log4j2 git commit: formatted XML
Posted by mi...@apache.org.
formatted XML
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/a8d8cfdc
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/a8d8cfdc
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/a8d8cfdc
Branch: refs/heads/LOG4J-1181
Commit: a8d8cfdc943deb81c8a157fbe74bdb9d17293586
Parents: e792dcd
Author: rpopma <rp...@apache.org>
Authored: Sun Dec 27 09:17:33 2015 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sun Dec 27 09:17:33 2015 +0900
----------------------------------------------------------------------
src/site/xdoc/faq.xml | 279 +++++++++++++++++++++++++++------------------
1 file changed, 165 insertions(+), 114 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a8d8cfdc/src/site/xdoc/faq.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/faq.xml b/src/site/xdoc/faq.xml
index 8dc198f..d6fa862 100644
--- a/src/site/xdoc/faq.xml
+++ b/src/site/xdoc/faq.xml
@@ -17,105 +17,134 @@
-->
<document>
- <properties>
- <title>Frequently Asked Questions</title>
- <author email="remkop@yahoo.com">Remko Popma</author>
- </properties>
+ <properties>
+ <title>Frequently Asked Questions</title>
+ <author email="remkop@yahoo.com">Remko Popma</author>
+ </properties>
- <body>
- <section name="Frequently Asked Questions">
+ <body>
+ <section name="Frequently Asked Questions">
<ul>
- <li><a href="#missing_core">I'm seeing this error "Unable to locate a logging implementation, using SimpleLogger".
- What is wrong?</a></li>
- <li><a href="#which_jars">Which JAR files do I need?</a></li>
- <li><a href="#config_location">How do I specify the configuration file location?</a></li>
- <li><a href="#config_from_code">How do I configure log4j2 in code without a configuration file?</a></li>
- <li><a href="#reconfig_from_code">How do I reconfigure log4j2 in code with a specific configuration file?</a></li>
- <li><a href="#shutdown">How do I shut down log4j2 in code?</a></li>
- <li><a href="#config_sep_appender_level">How do I send log messages with different levels to different appenders?</a></li>
- <li><a href="#troubleshooting">How do I debug my configuration?</a></li>
- <li><a href="#separate_log_files">How do I dynamically write to separate log files?</a></li>
- <li><a href="#reconfig_level_from_code">How do I set a logger's level programmatically?</a></li>
- <li><a href="#retention">How do I set my log archive retention policy? How do I delete old log archives?</a></li>
- <!--
- <li><a href="#custom_plugin">How do I get log4j2 to recognize my custom plugin?</a></li>
- -->
+ <li><a href="#missing_core">I'm seeing this error "Unable to locate a logging implementation, using SimpleLogger".
+ What is wrong?</a></li>
+ <li><a href="#which_jars">Which JAR files do I need?</a></li>
+ <li><a href="#config_location">How do I specify the configuration file location?</a></li>
+ <li><a href="#config_from_code">How do I configure log4j2 in code without a configuration file?</a></li>
+ <li><a href="#reconfig_from_code">How do I reconfigure log4j2 in code with a specific configuration file?</a></li>
+ <li><a href="#shutdown">How do I shut down log4j2 in code?</a></li>
+ <li><a href="#config_sep_appender_level">How do I send log messages with different levels to different appenders?</a></li>
+ <li><a href="#troubleshooting">How do I debug my configuration?</a></li>
+ <li><a href="#separate_log_files">How do I dynamically write to separate log files?</a></li>
+ <li><a href="#reconfig_level_from_code">How do I set a logger's level programmatically?</a></li>
+ <li><a href="#retention">How do I set my log archive retention policy? How do I delete old log archives?</a></li>
+ <!--
+ <li><a href="#custom_plugin">How do I get log4j2 to recognize my custom plugin?</a></li>
+ -->
</ul>
<subsection>
- <a name="missing_core" />
+ <a name="missing_core"/>
<h4>I'm seeing this error "Unable to locate a logging implementation, using SimpleLogger".
- What is wrong?</h4>
+ What is wrong?
+ </h4>
<p>You have the log4j-api-2.x jar file in your classpath but you still need to add the log4j-core-2.x jar to the
- classpath. (Also, it looks like you are using an old version of Log4j 2. You may want to upgrade.)</p>
+ classpath. (Also, it looks like you are using an old version of Log4j 2. You may want to upgrade.)
+ </p>
- <a name="which_jars" />
+ <a name="which_jars"/>
<h4>Which JAR files do I need?</h4>
<p>You need at least the log4j-api-2.x and the log4j-core-2.x jar files.</p>
<p>The other jars are necessary if your application calls the API
- of another logging framework and you want to route logging calls to the Log4j 2 implementation.</p>
- <p><img src="images/whichjar-2.x.png" alt="Diagram showing which JARs correspond to which systems" /></p>
+ of another logging framework and you want to route logging calls to the Log4j 2 implementation.
+ </p>
+ <p>
+ <img src="images/whichjar-2.x.png" alt="Diagram showing which JARs correspond to which systems"/>
+ </p>
<p>You can use the log4j-to-slf4j adapter jar when your application calls the Log4j 2 API and you
- want to route logging calls to a SLF4J implementation.</p>
- <p><img src="images/whichjar-slf4j-2.x.png" alt="Diagram showing the dependency flow to use Log4j 2 API with SLF4J" /></p>
+ want to route logging calls to a SLF4J implementation.
+ </p>
+ <p>
+ <img src="images/whichjar-slf4j-2.x.png"
+ alt="Diagram showing the dependency flow to use Log4j 2 API with SLF4J"/>
+ </p>
<p>Some of the Log4j components have features with optional dependencies.
The component page will have more detail.
- For example, the <a href="log4j-core/index.html">log4j-core component page</a>
- has an outline of which log4j-core features have external dependencies.</p>
+ For example, the
+ <a href="log4j-core/index.html">log4j-core component page</a>
+ has an outline of which log4j-core features have external dependencies.
+ </p>
- <a name="config_location" />
+ <a name="config_location"/>
<h4>How do I specify the configuration file location?</h4>
- <p>By default, Log4j looks for a configuration file named <b>log4j2.xml</b> (not log4j.xml) in the classpath.
- </p><p>
- You can also specify the full path of the configuration file with this system property:<br />
- <code>-Dlog4j.configurationFile=path/to/log4j2.xml</code></p>
+ <p>By default, Log4j looks for a configuration file named
+ <b>log4j2.xml</b>
+ (not log4j.xml) in the classpath.
+ </p>
+ <p>
+ You can also specify the full path of the configuration file with this system property:
+ <br/>
+ <code>-Dlog4j.configurationFile=path/to/log4j2.xml</code>
+ </p>
<p>Web applications can specify the Log4j configuration file location with a servlet context parameter.
- See <a href="http://logging.apache.org/log4j/2.x/manual/webapp.html#ContextParams">this section</a>
- of the Using Log4j 2 in Web Applications manual page.</p>
+ See
+ <a href="http://logging.apache.org/log4j/2.x/manual/webapp.html#ContextParams">this section</a>
+ of the Using Log4j 2 in Web Applications manual page.
+ </p>
- <a name="config_from_code" />
+ <a name="config_from_code"/>
<h4>How do I configure log4j2 in code without a configuration file?</h4>
- <p>Starting with version 2.4, Log4j 2 provides an <a href="manual/customconfig.html">API
- for programmatic configuration</a>.
- The new <a href="log4j-core/apidocs/org/apache/logging/log4j/core/config/builder/api/ConfigurationBuilder.html">ConfigurationBuilder
- API</a> allows you to create Configurations in code by constructing component definitions
- without requiring you to know about the internals of actual configuration objects like Loggers and Appenders.</p>
+ <p>Starting with version 2.4, Log4j 2 provides an<a href="manual/customconfig.html">API
+ for programmatic configuration</a>.
+ The new
+ <a href="log4j-core/apidocs/org/apache/logging/log4j/core/config/builder/api/ConfigurationBuilder.html">ConfigurationBuilder
+ API
+ </a>
+ allows you to create Configurations in code by constructing component definitions
+ without requiring you to know about the internals of actual configuration objects like Loggers and Appenders.
+ </p>
- <a name="reconfig_from_code" />
+ <a name="reconfig_from_code"/>
<h4>How do I reconfigure log4j2 in code with a specific configuration file?</h4>
<p>See the below example.
- Be aware that this LoggerContext class is not part of the public API so your code may break with any minor release.</p>
+ Be aware that this LoggerContext class is not part of the public API so your code may break with any minor release.
+ </p>
<pre class="prettyprint linenums">// import org.apache.logging.log4j.core.LoggerContext;
-LoggerContext context = (org.apache.logging.log4j.core.LoggerContext) LogManager.getContext(false);
-File file = new File("path/to/a/different/log4j2.xml");
+ LoggerContext context = (org.apache.logging.log4j.core.LoggerContext) LogManager.getContext(false);
+ File file = new File("path/to/a/different/log4j2.xml");
-// this will force a reconfiguration
-context.setConfigLocation(file.toURI());
-</pre>
+ // this will force a reconfiguration
+ context.setConfigLocation(file.toURI());
+ </pre>
- <a name="shutdown" />
+ <a name="shutdown"/>
<h4>How do I shut down log4j2 in code?</h4>
<p>Normally there is no need to do this manually.
- Each LoggerContext registers a shutdown hook that takes care of releasing resources
- when the JVM exits (unless system property <code>log4j.shutdownHookEnabled</code>
- is set to <code>false</code>).
- Web applications should include the log4j-web
- module in their classpath which disables the shutdown hook but instead
- cleans up log4j resources when the web application is stopped.</p>
+ Each LoggerContext registers a shutdown hook that takes care of releasing resources
+ when the JVM exits (unless system property
+ <code>log4j.shutdownHookEnabled</code>
+ is set to<code>false</code>).
+ Web applications should include the log4j-web
+ module in their classpath which disables the shutdown hook but instead
+ cleans up log4j resources when the web application is stopped.
+ </p>
<p>However, if you need to manually shut down log4j, you can do so
- as in the below example.
- Be aware that these classes are not part of the public API so your code may break with any minor release.</p>
+ as in the below example.
+ Be aware that these classes are not part of the public API so your code may break with any minor release.
+ </p>
<pre class="prettyprint linenums">// import org.apache.logging.log4j.core.LoggerContext;
-// import org.apache.logging.log4j.core.config.Configurator;
+ // import org.apache.logging.log4j.core.config.Configurator;
-// get the current context
-LoggerContext context = (LoggerContext) LogManager.getContext();
-Configurator.shutdown(context);</pre>
+ // get the current context
+ LoggerContext context = (LoggerContext) LogManager.getContext();
+ Configurator.shutdown(context);
+ </pre>
- <a name="config_sep_appender_level" />
+ <a name="config_sep_appender_level"/>
<h4>How do I send log messages with different levels to different appenders?</h4>
- You don't need to declare separate loggers to achieve this.
- You can set the logging level on the <code>AppenderRef</code> element.
+ You don't need to declare separate loggers to achieve this.
+ You can set the logging level on the
+ <code>AppenderRef</code>
+ element.
<pre class="prettyprint linenums"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
@@ -136,36 +165,51 @@ Configurator.shutdown(context);</pre>
</Loggers>
</Configuration>]]></pre>
- <a name="troubleshooting" />
+ <a name="troubleshooting"/>
<h4>How do I debug my configuration?</h4>
- <p>First, make sure you have <a href="#which_jars">the right jar files</a> on your classpath.
- You need at least log4j-api and log4j-core.</p>
+ <p>First, make sure you have
+ <a href="#which_jars">the right jar files</a>
+ on your classpath.
+ You need at least log4j-api and log4j-core.
+ </p>
<p>Next, check the name of your configuration file. By default, log4j2 will look
- for a configuration file named <code>log4j2.xml</code> on the classpath. Note the "2" in the file name!
- (See the <a href="manual/configuration.html#AutomaticConfiguration">configuration manual page</a>
- for more details.)</p>
+ for a configuration file named
+ <code>log4j2.xml</code>
+ on the classpath. Note the "2" in the file name!
+ (See the
+ <a href="manual/configuration.html#AutomaticConfiguration">configuration manual page</a>
+ for more details.)
+ </p>
<p>If the configuration file is found correctly, log4j2 internal status logging can be controlled by
- setting <code><Configuration status="trace"></code> in the configuration file.
- This will display detailed log4j2-internal
- log statements on the console about what happens during the configuration process.
- This may be useful to trouble-shoot configuration issues.
- By default the status logger level is WARN, so you only see notifications when there is a problem.
+ setting
+ <code><Configuration status="trace"></code>
+ in the configuration file.
+ This will display detailed log4j2-internal
+ log statements on the console about what happens during the configuration process.
+ This may be useful to trouble-shoot configuration issues.
+ By default the status logger level is WARN, so you only see notifications when there is a problem.
</p>
<p>If the configuration file is not found correctly, you can still enable
- log4j2 internal status logging by setting system property
- <code>-Dorg.apache.logging.log4j.simplelog.StatusLogger.level=TRACE</code>.</p>
+ log4j2 internal status logging by setting system property
+ <code>-Dorg.apache.logging.log4j.simplelog.StatusLogger.level=TRACE</code>.
+ </p>
- <a name="separate_log_files" />
+ <a name="separate_log_files"/>
<h4>How do I dynamically write to separate log files?</h4>
- <p>
- Look at the
- <a href="http://logging.apache.org/log4j/2.x/manual/appenders.html#RoutingAppender">RoutingAppender</a>.
- You can define multiple routes in the configuration,
- and put values in the <code>ThreadContext</code> map that determine
- which log file subsequent events in this thread get logged to.</p>
- <p>
- You can use the <code>ThreadContext</code> map value to determine the log file name.
- </p>
+ <p>
+ Look at the
+ <a href="http://logging.apache.org/log4j/2.x/manual/appenders.html#RoutingAppender">RoutingAppender</a>.
+ You can define multiple routes in the configuration,
+ and put values in the
+ <code>ThreadContext</code>
+ map that determine
+ which log file subsequent events in this thread get logged to.
+ </p>
+ <p>
+ You can use the
+ <code>ThreadContext</code>
+ map value to determine the log file name.
+ </p>
<pre class="prettyprint linenums"><![CDATA[<Routing name="Routing">
<Routes pattern="$${ctx:ROUTINGKEY}">
@@ -215,37 +259,44 @@ Configurator.shutdown(context);</pre>
</Routes>
</Routing>]]></pre>
- <a name="reconfig_level_from_code" />
+ <a name="reconfig_level_from_code"/>
<h4>How do I set a logger's level programmatically?</h4>
<p>You can set a logger's level with the class Configurator from Core module.
- Be aware that the Configuration class is not part of the public API.</p>
+ Be aware that the Configuration class is not part of the public API.
+ </p>
<pre class="prettyprint linenums">// org.apache.logging.log4j.core.config.Configurator;
-Configurator.setLevel("com.example.Foo", Level.DEBUG);
-
-// You can also set the root logger:
-Configurator.setRootLevel(Level.DEBUG);
-</pre>
-
- <a name="retention" />
- <h4>How do I set my log archive retention policy? How do I delete old log archives?</h4>
- <p>The <tt>DefaultRolloverStrategy</tt> of the Rolling File appender (and Rolling Random Access File
- appender) supports a <a href="manual/appenders.html#CustomDeleteOnRollover">Delete</a>
- element.</p>
- <p>Starting at a specified base directory, you can delete all files for which some condition
- holds true, for example all files that match a given file name pattern and are older
- than some number of days. More complex conditions are possible, and if the built-in
- conditions are not sufficient, users can provide
- custom conditions by creating
- <a href="manual/appenders.html#DeletePathCondition">plugin conditions</a> or by
- writing a <a href="manual/appenders.html#ScriptCondition">script condition</a>
- </p>
+ Configurator.setLevel("com.example.Foo", Level.DEBUG);
+
+ // You can also set the root logger:
+ Configurator.setRootLevel(Level.DEBUG);
+ </pre>
+
+ <a name="retention"/>
+ <h4>How do I set my log archive retention policy? How do I delete old log archives?</h4>
+ <p>The
+ <tt>DefaultRolloverStrategy</tt>
+ of the Rolling File appender (and Rolling Random Access File
+ appender) supports a
+ <a href="manual/appenders.html#CustomDeleteOnRollover">Delete</a>
+ element.
+ </p>
+ <p>Starting at a specified base directory, you can delete all files for which some condition
+ holds true, for example all files that match a given file name pattern and are older
+ than some number of days. More complex conditions are possible, and if the built-in
+ conditions are not sufficient, users can provide
+ custom conditions by creating
+ <a href="manual/appenders.html#DeletePathCondition">plugin conditions</a>
+ or by
+ writing a
+ <a href="manual/appenders.html#ScriptCondition">script condition</a>
+ </p>
<!--
<a name="custom_plugin" />
<h4>How do I get log4j2 to recognize my custom plugin?</h4>
-->
- </subsection>
- </section>
+ </subsection>
+ </section>
- </body>
+ </body>
</document>
[11/50] logging-log4j2 git commit: [LOG4J2-1233] Misleading Value In
Properties Example.
Posted by mi...@apache.org.
[LOG4J2-1233] Misleading Value In Properties Example.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/2d98964f
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/2d98964f
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/2d98964f
Branch: refs/heads/LOG4J-1181
Commit: 2d98964f749d408404b8f1043013a11427c6af97
Parents: a8d8cfd
Author: ggregory <gg...@apache.org>
Authored: Mon Dec 28 10:40:59 2015 -0800
Committer: ggregory <gg...@apache.org>
Committed: Mon Dec 28 10:40:59 2015 -0800
----------------------------------------------------------------------
src/changes/changes.xml | 3 +++
src/site/xdoc/manual/configuration.xml.vm | 2 +-
2 files changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2d98964f/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 8eb273e..070596d 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -37,6 +37,9 @@
<action issue="LOG4J2-1219" dev="ggregory" type="update">
Update SLF4J from 1.7.12 to 1.7.13.
</action>
+ <action issue="LOG4J2-1233" dev="ggregory" type="update" due-to="Bahri Gencsoy">
+ Misleading Value In Properties Example.
+ </action>
</release>
<release version="2.5" date="2015-12-06" description="GA Release 2.5">
<action issue="LOG4J2-324" dev="rpopma" type="fix">
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2d98964f/src/site/xdoc/manual/configuration.xml.vm
----------------------------------------------------------------------
diff --git a/src/site/xdoc/manual/configuration.xml.vm b/src/site/xdoc/manual/configuration.xml.vm
index 93b4663..ee14ce0 100644
--- a/src/site/xdoc/manual/configuration.xml.vm
+++ b/src/site/xdoc/manual/configuration.xml.vm
@@ -877,7 +877,7 @@ appender.list.filter.threshold.level = error
loggers = rolling
-logger.rolling.name = org.apache.logging.log4j.core.appender.rolling
+logger.rolling.name = com.example.my.app
logger.rolling.level = debug
logger.rolling.additivity = false
logger.rolling.appenderRefs = rolling
[22/50] logging-log4j2 git commit: Update maven-jetty-plugin from
6.1.10 to 6.1.26.
Posted by mi...@apache.org.
Update maven-jetty-plugin from 6.1.10 to 6.1.26.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/88b394c5
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/88b394c5
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/88b394c5
Branch: refs/heads/LOG4J-1181
Commit: 88b394c51cf047a3bfb924c090a6e6e7fa99b338
Parents: 7c659ce
Author: ggregory <gg...@apache.org>
Authored: Wed Dec 30 23:20:12 2015 -0800
Committer: ggregory <gg...@apache.org>
Committed: Wed Dec 30 23:20:12 2015 -0800
----------------------------------------------------------------------
log4j-samples/flume-remote/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/88b394c5/log4j-samples/flume-remote/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-samples/flume-remote/pom.xml b/log4j-samples/flume-remote/pom.xml
index 9d67887..015dbdf 100644
--- a/log4j-samples/flume-remote/pom.xml
+++ b/log4j-samples/flume-remote/pom.xml
@@ -107,7 +107,7 @@
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
- <version>6.1.10</version>
+ <version>6.1.26</version>
<configuration>
<contextPath>flumeAgent</contextPath>
<webXml>${project.build.directory}/web.xml</webXml>
[40/50] logging-log4j2 git commit: Formatting.
Posted by mi...@apache.org.
Formatting.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/fb6fd313
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/fb6fd313
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/fb6fd313
Branch: refs/heads/LOG4J-1181
Commit: fb6fd31312dffff15666577eed6513d62768b26a
Parents: 09c1fe2
Author: ggregory <gg...@apache.org>
Authored: Mon Jan 4 15:00:55 2016 -0800
Committer: ggregory <gg...@apache.org>
Committed: Mon Jan 4 15:00:55 2016 -0800
----------------------------------------------------------------------
.../apache/logging/log4j/core/appender/AsyncAppender.java | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/fb6fd313/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java
index a096b58..79b3ace 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java
@@ -242,15 +242,19 @@ public final class AsyncAppender extends AbstractAppender {
* @return The AsyncAppender.
*/
@PluginFactory
- public static AsyncAppender createAppender(@PluginElement("AppenderRef") final AppenderRef[] appenderRefs,
+ public static AsyncAppender createAppender(
+ // @formatter:off
+ @PluginElement("AppenderRef") final AppenderRef[] appenderRefs,
@PluginAttribute("errorRef") @PluginAliases("error-ref") final String errorRef,
@PluginAttribute(value = "blocking", defaultBoolean = true) final boolean blocking,
@PluginAttribute(value = "shutdownTimeout", defaultLong = 0L) final long shutdownTimeout,
@PluginAttribute(value = "bufferSize", defaultInt = DEFAULT_QUEUE_SIZE) final int size,
@PluginAttribute("name") final String name,
@PluginAttribute(value = "includeLocation", defaultBoolean = false) final boolean includeLocation,
- @PluginElement("Filter") final Filter filter, @PluginConfiguration final Configuration config,
+ @PluginElement("Filter") final Filter filter,
+ @PluginConfiguration final Configuration config,
@PluginAttribute(value = "ignoreExceptions", defaultBoolean = true) final boolean ignoreExceptions) {
+ // @formatter:on
if (name == null) {
LOGGER.error("No name provided for AsyncAppender");
return null;
[32/50] logging-log4j2 git commit: Better assert message.
Posted by mi...@apache.org.
Better assert message.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/55abe369
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/55abe369
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/55abe369
Branch: refs/heads/LOG4J-1181
Commit: 55abe369f3fdf60f074e153114481426740a56c8
Parents: ca3fa30
Author: ggregory <gg...@apache.org>
Authored: Sun Jan 3 09:14:59 2016 -0800
Committer: ggregory <gg...@apache.org>
Committed: Sun Jan 3 09:14:59 2016 -0800
----------------------------------------------------------------------
.../org/apache/logging/log4j/core/PatternSelectorTest.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55abe369/log4j-core/src/test/java/org/apache/logging/log4j/core/PatternSelectorTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/PatternSelectorTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/PatternSelectorTest.java
index 7ab7583..7e168bd 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/PatternSelectorTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/PatternSelectorTest.java
@@ -47,7 +47,7 @@ public class PatternSelectorTest {
assertNotNull("No ListAppender", app);
List<String> messages = app.getMessages();
assertNotNull("No Messages", messages);
- assertTrue("Incorrect number of messages. Expected 3, Actual " + messages.size(), messages.size() == 3);
+ assertTrue("Incorrect number of messages. Expected 3, Actual " + messages.size() + ": " + messages, messages.size() == 3);
final String expect = String.format("[TRACE] TestMarkerPatternSelector ====== "
+ "o.a.l.l.c.PatternSelectorTest.testMarkerPatternSelector:43 entry ======%n");
assertEquals(expect, messages.get(0));
@@ -67,7 +67,7 @@ public class PatternSelectorTest {
assertNotNull("No ListAppender", app);
List<String> messages = app.getMessages();
assertNotNull("No Messages", messages);
- assertTrue("Incorrect number of messages. Expected 4, Actual " + messages.size(), messages.size() == 4);
+ assertTrue("Incorrect number of messages. Expected 4, Actual " + messages.size() + ": " + messages, messages.size() == 4);
String expect = "[TRACE] TestScriptPatternSelector ====== " +
"o.a.l.l.c.PatternSelectorTest.testScriptPatternSelector:62 entry ======" + Constants.LINE_SEPARATOR;
assertEquals(expect, messages.get(0));
@@ -90,7 +90,7 @@ public class PatternSelectorTest {
assertNotNull("No ListAppender", app);
List<String> messages = app.getMessages();
assertNotNull("No Messages", messages);
- assertTrue("Incorrect number of messages. Expected 4, Actual " + messages.size(), messages.size() == 4);
+ assertTrue("Incorrect number of messages. Expected 4, Actual " + messages.size() + ": " + messages, messages.size() == 4);
String expect = "[TRACE] TestJavaScriptPatternSelector ====== " +
"o.a.l.l.c.PatternSelectorTest.testJavaScriptPatternSelector:85 entry ======" + Constants.LINE_SEPARATOR;
assertEquals(expect, messages.get(0));
[29/50] logging-log4j2 git commit: Fix Javadoc typo.
Posted by mi...@apache.org.
Fix Javadoc typo.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/7af6c052
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/7af6c052
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/7af6c052
Branch: refs/heads/LOG4J-1181
Commit: 7af6c0525da3e979186efc470c4d69daba97725d
Parents: 15b087c
Author: ggregory <gg...@apache.org>
Authored: Fri Jan 1 09:12:56 2016 -0800
Committer: ggregory <gg...@apache.org>
Committed: Fri Jan 1 09:12:56 2016 -0800
----------------------------------------------------------------------
.../main/java/org/apache/logging/log4j/core/layout/HtmlLayout.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7af6c052/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/HtmlLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/HtmlLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/HtmlLayout.java
index a05f85e..c2bb4c6 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/HtmlLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/HtmlLayout.java
@@ -289,7 +289,7 @@ public final class HtmlLayout extends AbstractStringLayout {
/**
* Returns the appropriate HTML footers.
- * @return the footer as a byet array.
+ * @return the footer as a byte array.
*/
@Override
public byte[] getFooter() {
[26/50] logging-log4j2 git commit: Add tests for [LOG4J2-1232]
Incorrect log rotation in last week of year.
Posted by mi...@apache.org.
Add tests for [LOG4J2-1232] Incorrect log rotation in last week of year.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/f28d3d8b
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/f28d3d8b
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/f28d3d8b
Branch: refs/heads/LOG4J-1181
Commit: f28d3d8b42d23109f400980ae5d93c5c953bab40
Parents: d7efe9a
Author: ggregory <gg...@apache.org>
Authored: Thu Dec 31 18:51:06 2015 -0800
Committer: ggregory <gg...@apache.org>
Committed: Thu Dec 31 18:51:06 2015 -0800
----------------------------------------------------------------------
.../core/appender/rolling/PatternProcessorTest.java | 13 +++++++++++++
1 file changed, 13 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f28d3d8b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessorTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessorTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessorTest.java
index cebb0f4..c06b815 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessorTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessorTest.java
@@ -171,6 +171,19 @@ public class PatternProcessorTest {
}
@Test
+ public void testGetNextTimeHourlyReturnsFirstMinuteOfNextYear() {
+ final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM-dd-HH}.log.gz");
+ final Calendar initial = Calendar.getInstance();
+ initial.set(2015, Calendar.DECEMBER, 31, 23, 31, 59);
+ final long actual = pp.getNextTime(initial.getTimeInMillis(), 1, false);
+
+ final Calendar expected = Calendar.getInstance();
+ expected.set(2016, Calendar.JANUARY, 1, 0, 0, 0);
+ expected.set(Calendar.MILLISECOND, 0);
+ assertEquals(format(expected.getTimeInMillis()), format(actual));
+ }
+
+ @Test
public void testGetNextTimeHourlyReturnsFirstMinuteOfNextHour2() {
final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM-dd-HH}.log.gz");
final Calendar initial = Calendar.getInstance();
[47/50] logging-log4j2 git commit: Group fixes together.
Posted by mi...@apache.org.
Group fixes together.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/6971f584
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/6971f584
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/6971f584
Branch: refs/heads/LOG4J-1181
Commit: 6971f5845ebea8b466dda4ab31d781ce33a30911
Parents: 102bcec
Author: ggregory <gg...@apache.org>
Authored: Mon Jan 11 10:21:50 2016 -0800
Committer: ggregory <gg...@apache.org>
Committed: Mon Jan 11 10:21:50 2016 -0800
----------------------------------------------------------------------
src/changes/changes.xml | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/6971f584/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index b8fe598..17c81f6 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -24,9 +24,6 @@
</properties>
<body>
<release version="2.5.1" date="201Y-MM-DD" description="GA Release 2.5.1">
- <action issue="LOG4J2-1248" dev="rpopma" type="fix">
- Fixed broken nanotime in pattern layout.
- </action>
<action issue="LOG4J2-1080" dev="rpopma" type="add">
Added option to discard events below a certain log level if the async logger ring buffer
or async appender queue remaining capacity falls below a certain ratio.
@@ -43,6 +40,9 @@
<action issue="LOG4J2-1192" dev="ggregory" type="add" due-to="Jörg Bretschneider, Gary Gregory">
Dynamic Subject for SMTP Appender.
</action>
+ <action issue="LOG4J2-1248" dev="rpopma" type="fix">
+ Fixed broken nanotime in pattern layout.
+ </action>
<action issue="LOG4J2-908" dev="ggregory" type="fix" due-to="Konstantinos Liakos, Patrick Flaherty, Robin Coe, Gary Gregory">
JSONLayout doesn't add a comma between log events.
</action>
[15/50] logging-log4j2 git commit: [LOG4J2-1238]
org.apache.logging.log4j.core.net.TcpSocketManager does not display stack
traces.
Posted by mi...@apache.org.
[LOG4J2-1238] org.apache.logging.log4j.core.net.TcpSocketManager does
not display stack traces.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/f965d515
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/f965d515
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/f965d515
Branch: refs/heads/LOG4J-1181
Commit: f965d51552b29ec602378c9a3e1cff2b97c28ebf
Parents: aa2c0cd
Author: ggregory <gg...@apache.org>
Authored: Wed Dec 30 16:49:51 2015 -0800
Committer: ggregory <gg...@apache.org>
Committed: Wed Dec 30 16:49:51 2015 -0800
----------------------------------------------------------------------
.../java/org/apache/logging/log4j/core/net/TcpSocketManager.java | 4 ++--
src/changes/changes.xml | 3 +++
2 files changed, 5 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f965d515/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TcpSocketManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TcpSocketManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TcpSocketManager.java
index f9aabb3..a487438 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TcpSocketManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TcpSocketManager.java
@@ -278,7 +278,7 @@ public class TcpSocketManager extends AbstractSocketManager {
try {
inetAddress = InetAddress.getByName(data.host);
} catch (final UnknownHostException ex) {
- LOGGER.error("Could not find address of " + data.host, ex);
+ LOGGER.error("Could not find address of " + data.host, ex, ex);
return null;
}
try {
@@ -289,7 +289,7 @@ public class TcpSocketManager extends AbstractSocketManager {
return new TcpSocketManager(name, os, socket, inetAddress, data.host, data.port,
data.connectTimeoutMillis, data.delayMillis, data.immediateFail, data.layout);
} catch (final IOException ex) {
- LOGGER.error("TcpSocketManager (" + name + ") " + ex);
+ LOGGER.error("TcpSocketManager (" + name + ") " + ex, ex);
os = new ByteArrayOutputStream();
}
if (data.delayMillis == 0) {
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f965d515/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index cd9ca6f..dee5215 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -31,6 +31,9 @@
<action issue="LOG4J2-908" dev="ggregory" type="fix" due-to="Konstantinos Liakos, Patrick Flaherty, Robin Coe, Gary Gregory">
JSONLayout doesn't add a comma between log events.
</action>
+ <action issue="LOG4J2-1238" dev="ggregory" type="fix">
+ org.apache.logging.log4j.core.net.TcpSocketManager does not display stack traces.
+ </action>
<action issue="LOG4J2-1212" dev="rpopma" type="fix">
Fix documentation to correctly specify the blocking wait strategy as the default for async loggers.
</action>
[35/50] logging-log4j2 git commit: Update Surefire and Failsafe to
2.19.1 works for me locally,
which fixes a 2.19 bug: https://issues.apache.org/jira/browse/SUREFIRE-1193.
Let's see what happens on Jenkins.
Posted by mi...@apache.org.
Update Surefire and Failsafe to 2.19.1 works for me locally, which fixes
a 2.19 bug: https://issues.apache.org/jira/browse/SUREFIRE-1193. Let's
see what happens on Jenkins.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/4156fbc7
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/4156fbc7
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/4156fbc7
Branch: refs/heads/LOG4J-1181
Commit: 4156fbc76f20c45d16368bec95f43c20f93ae8a8
Parents: c3d8ce8
Author: ggregory <gg...@apache.org>
Authored: Sun Jan 3 22:38:44 2016 -0800
Committer: ggregory <gg...@apache.org>
Committed: Sun Jan 3 22:38:44 2016 -0800
----------------------------------------------------------------------
pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4156fbc7/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index e2778af..ef760ba 100644
--- a/pom.xml
+++ b/pom.xml
@@ -201,8 +201,8 @@
<javadoc.plugin.version>2.10.3</javadoc.plugin.version>
<!-- surefire.plugin.version 2.18 yields http://jira.codehaus.org/browse/SUREFIRE-1121, which is fixed in 2.18.1 -->
<!-- surefire.plugin.version 2.19 yields https://issues.apache.org/jira/browse/SUREFIRE-1193. -->
- <surefire.plugin.version>2.18.1</surefire.plugin.version>
- <failsafe.plugin.version>2.18.1</failsafe.plugin.version>
+ <surefire.plugin.version>2.19.1</surefire.plugin.version>
+ <failsafe.plugin.version>2.19.1</failsafe.plugin.version>
<checkstyle.plugin.version>2.17</checkstyle.plugin.version>
<rat.plugin.version>0.11</rat.plugin.version>
<pdf.plugin.version>1.2</pdf.plugin.version>
[43/50] logging-log4j2 git commit: [LOG4J2-1230] Don't concatenate
SYSLOG Messages.
Posted by mi...@apache.org.
[LOG4J2-1230] Don't concatenate SYSLOG Messages.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/5b1404b6
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/5b1404b6
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/5b1404b6
Branch: refs/heads/LOG4J-1181
Commit: 5b1404b6b7ed4a3616111d507ebd819f8a07dd7d
Parents: 711278b
Author: ggregory <gg...@apache.org>
Authored: Mon Jan 4 23:32:11 2016 -0800
Committer: ggregory <gg...@apache.org>
Committed: Mon Jan 4 23:32:11 2016 -0800
----------------------------------------------------------------------
.../appender/AbstractOutputStreamAppender.java | 13 ++------
.../log4j/core/appender/FileManager.java | 6 ++--
.../core/appender/MemoryMappedFileManager.java | 4 +--
.../core/appender/OutputStreamManager.java | 32 ++++++++++++++++++--
.../core/appender/RandomAccessFileManager.java | 6 ++--
.../appender/rolling/RollingFileManager.java | 4 +--
.../rolling/RollingRandomAccessFileManager.java | 6 ++--
.../log4j/core/net/TcpSocketManager.java | 8 +++--
.../appender/RandomAccessFileManagerTest.java | 2 +-
.../RollingRandomAccessFileManagerTest.java | 9 +++---
src/changes/changes.xml | 3 ++
11 files changed, 59 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/5b1404b6/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractOutputStreamAppender.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractOutputStreamAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractOutputStreamAppender.java
index 5ab28d5..9a4cfde 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractOutputStreamAppender.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractOutputStreamAppender.java
@@ -44,9 +44,6 @@ public abstract class AbstractOutputStreamAppender<M extends OutputStreamManager
private final M manager;
- private final ReadWriteLock rwLock = new ReentrantReadWriteLock();
- private final Lock readLock = rwLock.readLock();
-
/**
* Instantiates a WriterAppender and set the output destination to a new {@link java.io.OutputStreamWriter}
* initialized with <code>os</code> as its {@link java.io.OutputStream}.
@@ -107,20 +104,14 @@ public abstract class AbstractOutputStreamAppender<M extends OutputStreamManager
*/
@Override
public void append(final LogEvent event) {
- readLock.lock();
try {
final byte[] bytes = getLayout().toByteArray(event);
- if (bytes.length > 0) {
- manager.write(bytes);
- if (this.immediateFlush || event.isEndOfBatch()) {
- manager.flush();
- }
+ if (bytes != null && bytes.length > 0) {
+ manager.write(bytes, this.immediateFlush || event.isEndOfBatch());
}
} catch (final AppenderLoggingException ex) {
error("Unable to write to stream " + manager.getName() + " for appender " + getName());
throw ex;
- } finally {
- readLock.unlock();
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/5b1404b6/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java
index 827a9c0..4de34ad 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java
@@ -76,7 +76,7 @@ public class FileManager extends OutputStreamManager {
}
@Override
- protected synchronized void write(final byte[] bytes, final int offset, final int length) {
+ protected synchronized void write(final byte[] bytes, final int offset, final int length, final boolean immediateFlush) {
if (isLocking) {
final FileChannel channel = ((FileOutputStream) getOutputStream()).getChannel();
@@ -90,7 +90,7 @@ public class FileManager extends OutputStreamManager {
files strings are configured that somehow map to the same file.*/
final FileLock lock = channel.lock(0, Long.MAX_VALUE, false);
try {
- super.write(bytes, offset, length);
+ super.write(bytes, offset, length, immediateFlush);
} finally {
lock.release();
}
@@ -99,7 +99,7 @@ public class FileManager extends OutputStreamManager {
}
} else {
- super.write(bytes, offset, length);
+ super.write(bytes, offset, length, immediateFlush);
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/5b1404b6/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java
index 7bd0eb5..9335ddb 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java
@@ -111,8 +111,8 @@ public class MemoryMappedFileManager extends OutputStreamManager {
}
@Override
- protected synchronized void write(final byte[] bytes, int offset, int length) {
- super.write(bytes, offset, length); // writes to dummy output stream
+ protected synchronized void write(final byte[] bytes, int offset, int length, final boolean immediateFlush) {
+ super.write(bytes, offset, length, immediateFlush); // writes to dummy output stream
while (length > mappedBuffer.remaining()) {
final int chunk = mappedBuffer.remaining();
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/5b1404b6/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java
index 99c3321..42eaa34 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java
@@ -117,10 +117,26 @@ public class OutputStreamManager extends AbstractManager {
* @param length The number of bytes to write.
* @throws AppenderLoggingException if an error occurs.
*/
- protected synchronized void write(final byte[] bytes, final int offset, final int length) {
- //System.out.println("write " + count);
+ protected void write(final byte[] bytes, final int offset, final int length) {
+ write(bytes, offset, length, false);
+ }
+
+ /**
+ * Some output streams synchronize writes while others do not. Synchronizing here insures that
+ * log events won't be intertwined.
+ * @param bytes The serialized Log event.
+ * @param offset The offset into the byte array.
+ * @param length The number of bytes to write.
+ * @param immediateFlush flushes immediately after writing.
+ * @throws AppenderLoggingException if an error occurs.
+ */
+ protected synchronized void write(final byte[] bytes, final int offset, final int length, boolean immediateFlush) {
+ // System.out.println("write " + count);
try {
os.write(bytes, offset, length);
+ if (immediateFlush) {
+ os.flush();
+ }
} catch (final IOException ex) {
final String msg = "Error writing to stream " + getName();
throw new AppenderLoggingException(msg, ex);
@@ -133,7 +149,17 @@ public class OutputStreamManager extends AbstractManager {
* @throws AppenderLoggingException if an error occurs.
*/
protected void write(final byte[] bytes) {
- write(bytes, 0, bytes.length);
+ write(bytes, 0, bytes.length, false);
+ }
+
+ /**
+ * Some output streams synchronize writes while others do not.
+ * @param bytes The serialized Log event.
+ * @param writeAndFlush If true, flushes after writing.
+ * @throws AppenderLoggingException if an error occurs.
+ */
+ protected void write(final byte[] bytes, boolean immediateFlush) {
+ write(bytes, 0, bytes.length, immediateFlush);
}
protected synchronized void close() {
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/5b1404b6/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java
index c6627df..12af7ee 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java
@@ -85,8 +85,8 @@ public class RandomAccessFileManager extends OutputStreamManager {
}
@Override
- protected synchronized void write(final byte[] bytes, int offset, int length) {
- super.write(bytes, offset, length); // writes to dummy output stream
+ protected synchronized void write(final byte[] bytes, int offset, int length, final boolean immediateFlush) {
+ super.write(bytes, offset, length, immediateFlush); // writes to dummy output stream
int chunk = 0;
do {
@@ -99,7 +99,7 @@ public class RandomAccessFileManager extends OutputStreamManager {
length -= chunk;
} while (length > 0);
- if (isImmediateFlush || isEndOfBatch.get() == Boolean.TRUE) {
+ if (immediateFlush || isImmediateFlush || isEndOfBatch.get() == Boolean.TRUE) {
flush();
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/5b1404b6/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
index 48ff472..fc77a98 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
@@ -89,9 +89,9 @@ public class RollingFileManager extends FileManager {
}
@Override
- protected synchronized void write(final byte[] bytes, final int offset, final int length) {
+ protected synchronized void write(final byte[] bytes, final int offset, final int length, final boolean immediateFlush) {
size += length;
- super.write(bytes, offset, length);
+ super.write(bytes, offset, length, immediateFlush);
}
/**
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/5b1404b6/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java
index b732feb..56a1b47 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java
@@ -94,8 +94,8 @@ public class RollingRandomAccessFileManager extends RollingFileManager {
}
@Override
- protected synchronized void write(final byte[] bytes, int offset, int length) {
- super.write(bytes, offset, length); // writes to dummy output stream, needed to track file size
+ protected synchronized void write(final byte[] bytes, int offset, int length, final boolean immediateFlush) {
+ super.write(bytes, offset, length, immediateFlush); // writes to dummy output stream, needed to track file size
int chunk = 0;
do {
@@ -108,7 +108,7 @@ public class RollingRandomAccessFileManager extends RollingFileManager {
length -= chunk;
} while (length > 0);
- if (isImmediateFlush || isEndOfBatch.get() == Boolean.TRUE) {
+ if (immediateFlush || isImmediateFlush || isEndOfBatch.get() == Boolean.TRUE) {
flush();
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/5b1404b6/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TcpSocketManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TcpSocketManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TcpSocketManager.java
index a487438..d518aee 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TcpSocketManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TcpSocketManager.java
@@ -116,7 +116,7 @@ public class TcpSocketManager extends AbstractSocketManager {
}
@Override
- protected void write(final byte[] bytes, final int offset, final int length) {
+ protected void write(final byte[] bytes, final int offset, final int length, boolean immediateFlush) {
if (socket == null) {
if (connector != null && !immediateFail) {
connector.latch();
@@ -128,7 +128,11 @@ public class TcpSocketManager extends AbstractSocketManager {
}
synchronized (this) {
try {
- getOutputStream().write(bytes, offset, length);
+ final OutputStream outputStream = getOutputStream();
+ outputStream.write(bytes, offset, length);
+ if (immediateFlush) {
+ outputStream.flush();
+ }
} catch (final IOException ex) {
if (retry && connector == null) {
connector = new Reconnector(this);
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/5b1404b6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileManagerTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileManagerTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileManagerTest.java
index f127db3..07e8ab2 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileManagerTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileManagerTest.java
@@ -130,7 +130,7 @@ public class RandomAccessFileManagerTest {
final RandomAccessFileManager manager = RandomAccessFileManager.getFileManager(
file.getAbsolutePath(), isAppend, true, RandomAccessFileManager.DEFAULT_BUFFER_SIZE, null, null);
- manager.write(bytes, 0, bytes.length);
+ manager.write(bytes, 0, bytes.length, false);
final int expected = bytes.length * 2;
assertEquals("appended, not overwritten", expected, file.length());
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/5b1404b6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java
index d96d75e..4baddac 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java
@@ -66,7 +66,7 @@ public class RollingRandomAccessFileManagerTest {
final int size = RollingRandomAccessFileManager.DEFAULT_BUFFER_SIZE * 3;
final byte[] data = new byte[size];
- manager.write(data, 0, data.length); // no buffer overflow exception
+ manager.write(data, 0, data.length, flushNow); // no buffer overflow exception
// buffer is full but not flushed yet
assertEquals(RollingRandomAccessFileManager.DEFAULT_BUFFER_SIZE * 2,
@@ -97,7 +97,7 @@ public class RollingRandomAccessFileManagerTest {
final int size = RollingRandomAccessFileManager.DEFAULT_BUFFER_SIZE * 3 + 1;
final byte[] data = new byte[size];
- manager.write(data, 0, data.length); // no exception
+ manager.write(data, 0, data.length, flushNow); // no exception
assertEquals(RollingRandomAccessFileManager.DEFAULT_BUFFER_SIZE * 3,
raf.length());
@@ -146,13 +146,14 @@ public class RollingRandomAccessFileManagerTest {
}
assertThat("all flushed to disk", file, hasLength(bytes.length));
+ final boolean immediateFlush = true;
final RollingRandomAccessFileManager manager = RollingRandomAccessFileManager
.getRollingRandomAccessFileManager(
//
- file.getAbsolutePath(), Strings.EMPTY, isAppend, true, RollingRandomAccessFileManager.DEFAULT_BUFFER_SIZE,
+ file.getAbsolutePath(), Strings.EMPTY, isAppend, immediateFlush, RollingRandomAccessFileManager.DEFAULT_BUFFER_SIZE,
new SizeBasedTriggeringPolicy(Long.MAX_VALUE), //
null, null, null);
- manager.write(bytes, 0, bytes.length);
+ manager.write(bytes, 0, bytes.length, immediateFlush);
final int expected = bytes.length * 2;
assertThat("appended, not overwritten", file, hasLength(expected));
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/5b1404b6/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 0664458..3182a0c 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -37,6 +37,9 @@
<action issue="LOG4J2-908" dev="ggregory" type="fix" due-to="Konstantinos Liakos, Patrick Flaherty, Robin Coe, Gary Gregory">
JSONLayout doesn't add a comma between log events.
</action>
+ <action issue="LOG4J2-1230" dev="ggregory" type="fix" due-to="Vladimir Hudec, Ralph Goers, Gary Gregory">
+ Don't concatenate SYSLOG Messages.
+ </action>
<action issue="LOG4J2-1238" dev="ggregory" type="fix">
org.apache.logging.log4j.core.net.TcpSocketManager and other classes does not report internal exceptions to the status logger.
</action>
[09/50] logging-log4j2 git commit: LOG4J2-435 grammar fix
Posted by mi...@apache.org.
LOG4J2-435 grammar fix
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/e792dcdb
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/e792dcdb
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/e792dcdb
Branch: refs/heads/LOG4J-1181
Commit: e792dcdb74ae4b9f7452eabbd39a216b2abd4a57
Parents: d5f7350
Author: rpopma <rp...@apache.org>
Authored: Sun Dec 27 09:08:23 2015 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sun Dec 27 09:08:23 2015 +0900
----------------------------------------------------------------------
src/site/xdoc/manual/appenders.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/e792dcdb/src/site/xdoc/manual/appenders.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/manual/appenders.xml b/src/site/xdoc/manual/appenders.xml
index 817fb1f..9dcb0c2 100644
--- a/src/site/xdoc/manual/appenders.xml
+++ b/src/site/xdoc/manual/appenders.xml
@@ -2751,8 +2751,8 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
</Policies>
<DefaultRolloverStrategy max="100">
<!--
- Nested conditions: the inner condition is only evaluated for files
- where the outer conditions are true.
+ Nested conditions: the inner condition is only evaluated on files
+ for which the outer conditions are true.
-->
<Delete basePath="${baseDir}" maxDepth="2">
<IfFileName glob="*/app-*.log.gz">
[33/50] logging-log4j2 git commit: Better assert message.
Posted by mi...@apache.org.
Better assert message.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/69441343
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/69441343
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/69441343
Branch: refs/heads/LOG4J-1181
Commit: 6944134328e55f16ed2ca80c71e2119ddc5d8bb7
Parents: 55abe36
Author: ggregory <gg...@apache.org>
Authored: Sun Jan 3 09:48:05 2016 -0800
Committer: ggregory <gg...@apache.org>
Committed: Sun Jan 3 09:48:05 2016 -0800
----------------------------------------------------------------------
.../log4j/core/layout/PatternLayoutMainMapLookupTest.java | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/69441343/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutMainMapLookupTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutMainMapLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutMainMapLookupTest.java
index b476097..08386ba 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutMainMapLookupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutMainMapLookupTest.java
@@ -55,9 +55,10 @@ public class PatternLayoutMainMapLookupTest {
logger.info("Hello World");
final List<String> messages = listApp.getMessages();
Assert.assertFalse(messages.isEmpty());
- Assert.assertEquals("Header: value0", messages.get(0));
+ final String messagesStr = messages.toString();
+ Assert.assertEquals(messagesStr, "Header: value0", messages.get(0));
listApp.stop();
- Assert.assertEquals("Footer: value1", messages.get(2));
+ Assert.assertEquals(messagesStr, "Footer: value1", messages.get(2));
}
}
[19/50] logging-log4j2 git commit: [LOG4J2-1239] Update Jackson from
2.6.3 to 2.6.4.
Posted by mi...@apache.org.
[LOG4J2-1239] Update Jackson from 2.6.3 to 2.6.4.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/39bf837d
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/39bf837d
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/39bf837d
Branch: refs/heads/LOG4J-1181
Commit: 39bf837dca77699069f898bd57d799d4295f1a3f
Parents: 673756b
Author: ggregory <gg...@apache.org>
Authored: Wed Dec 30 20:29:22 2015 -0800
Committer: ggregory <gg...@apache.org>
Committed: Wed Dec 30 20:29:22 2015 -0800
----------------------------------------------------------------------
pom.xml | 2 +-
src/changes/changes.xml | 3 +++
2 files changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/39bf837d/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index bb616d0..ddec4d5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -190,7 +190,7 @@
<slf4jVersion>1.7.13</slf4jVersion>
<logbackVersion>1.1.3</logbackVersion>
<jackson1Version>1.9.13</jackson1Version>
- <jackson2Version>2.6.3</jackson2Version>
+ <jackson2Version>2.6.4</jackson2Version>
<springVersion>3.2.13.RELEASE</springVersion>
<flumeVersion>1.6.0</flumeVersion>
<disruptorVersion>3.3.2</disruptorVersion>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/39bf837d/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index a6fdd65..8892b2b 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -43,6 +43,9 @@
<action issue="LOG4J2-1219" dev="ggregory" type="update">
Update SLF4J from 1.7.12 to 1.7.13.
</action>
+ <action issue="LOG4J2-1239" dev="ggregory" type="update">
+ Update Jackson from 2.6.3 to 2.6.4.
+ </action>
<action issue="LOG4J2-1233" dev="ggregory" type="update" due-to="Bahri Gencsoy">
Misleading Value In Properties Example.
</action>
[13/50] logging-log4j2 git commit: [LOG4J2-908] JSONLayout doesn't
add a comma between log events.
Posted by mi...@apache.org.
[LOG4J2-908] JSONLayout doesn't add a comma between log events.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/7da92dee
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/7da92dee
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/7da92dee
Branch: refs/heads/LOG4J-1181
Commit: 7da92deeae90be56ed314a2721b9a8e683442cd1
Parents: 70ddbaf
Author: ggregory <gg...@apache.org>
Authored: Tue Dec 29 16:57:01 2015 -0800
Committer: ggregory <gg...@apache.org>
Committed: Tue Dec 29 16:57:01 2015 -0800
----------------------------------------------------------------------
.../core/layout/AbstractJacksonLayout.java | 19 ++++++--
.../log4j/core/layout/AbstractLayout.java | 9 ++++
.../logging/log4j/core/layout/JsonLayout.java | 51 ++++++++++++--------
src/changes/changes.xml | 3 ++
4 files changed, 60 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7da92dee/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
index ca966fb..3b122e1 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
@@ -16,12 +16,16 @@
*/
package org.apache.logging.log4j.core.layout;
+import java.io.IOException;
+import java.io.Writer;
import java.nio.charset.Charset;
import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.util.StringBuilderWriter;
import org.apache.logging.log4j.util.Strings;
-import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.JsonGenerationException;
+import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectWriter;
abstract class AbstractJacksonLayout extends AbstractStringLayout {
@@ -51,13 +55,22 @@ abstract class AbstractJacksonLayout extends AbstractStringLayout {
*/
@Override
public String toSerializable(final LogEvent event) {
+ StringBuilderWriter writer = new StringBuilderWriter();
try {
- return this.objectWriter.writeValueAsString(event) + eol;
- } catch (final JsonProcessingException e) {
+ toSerializable(event, writer);
+ return writer.toString();
+ } catch (final IOException e) {
// Should this be an ISE or IAE?
LOGGER.error(e);
return Strings.EMPTY;
}
}
+ public void toSerializable(final LogEvent event, Writer writer)
+ throws JsonGenerationException, JsonMappingException, IOException {
+ objectWriter.writeValue(writer, event);
+ writer.write(eol);
+ markEvent();
+ }
+
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7da92dee/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractLayout.java
index 4fa1d8e..9c5166e 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractLayout.java
@@ -50,6 +50,11 @@ public abstract class AbstractLayout<T extends Serializable> implements Layout<T
protected final byte[] footer;
/**
+ * The count of events successfully processed by this layout.
+ */
+ protected long eventCount;
+
+ /**
* Constructs a layout with an optional header and footer.
*
* @param header
@@ -87,4 +92,8 @@ public abstract class AbstractLayout<T extends Serializable> implements Layout<T
public byte[] getHeader() {
return header;
}
+
+ protected void markEvent() {
+ eventCount++;
+ }
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7da92dee/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java
index 04cda2d..5f3969c 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java
@@ -16,12 +16,15 @@
*/
package org.apache.logging.log4j.core.layout;
+import java.io.IOException;
+import java.io.Writer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import org.apache.logging.log4j.core.Layout;
+import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.config.Node;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
@@ -32,8 +35,9 @@ import org.apache.logging.log4j.core.config.plugins.PluginFactory;
*
* <h3>Complete well-formed JSON vs. fragment JSON</h3>
* <p>
- * If you configure {@code complete="true"}, the appender outputs a well-formed JSON document. By default, with {@code complete="false"},
- * you should include the output as an <em>external file</em> in a separate file to form a well-formed JSON document.
+ * If you configure {@code complete="true"}, the appender outputs a well-formed JSON document. By default, with
+ * {@code complete="false"}, you should include the output as an <em>external file</em> in a separate file to form a
+ * well-formed JSON document.
* </p>
* <p>
* A well-formed JSON event follows this pattern:
@@ -773,22 +777,22 @@ import org.apache.logging.log4j.core.config.plugins.PluginFactory;
}
* </pre>
* <p>
- * If {@code complete="false"}, the appender does not write the JSON open array character "[" at the start of the document. and "]" and the
- * end.
+ * If {@code complete="false"}, the appender does not write the JSON open array character "[" at the start of the
+ * document. and "]" and the end.
* </p>
* <p>
* This approach enforces the independence of the JsonLayout and the appender where you embed it.
* </p>
* <h3>Encoding</h3>
* <p>
- * Appenders using this layout should have their {@code charset} set to {@code UTF-8} or {@code UTF-16}, otherwise events containing non
- * ASCII characters could result in corrupted log files.
+ * Appenders using this layout should have their {@code charset} set to {@code UTF-8} or {@code UTF-16}, otherwise
+ * events containing non ASCII characters could result in corrupted log files.
* </p>
* <h3>Pretty vs. compact XML</h3>
* <p>
- * By default, the JSON layout is not compact (a.k.a. not "pretty") with {@code compact="false"}, which means the appender uses end-of-line
- * characters and indents lines to format the text. If {@code compact="true"}, then no end-of-line or indentation is used. Message content
- * may contain, of course, escaped end-of-lines.
+ * By default, the JSON layout is not compact (a.k.a. not "pretty") with {@code compact="false"}, which means the
+ * appender uses end-of-line characters and indents lines to format the text. If {@code compact="true"}, then no
+ * end-of-line or indentation is used. Message content may contain, of course, escaped end-of-lines.
* </p>
*/
@Plugin(name = "JsonLayout", category = Node.CATEGORY, elementType = Layout.ELEMENT_TYPE, printObject = true)
@@ -798,9 +802,10 @@ public final class JsonLayout extends AbstractJacksonLayout {
private static final long serialVersionUID = 1L;
- protected JsonLayout(final boolean locationInfo, final boolean properties, final boolean complete, final boolean compact,
- final boolean eventEol, final Charset charset) {
- super(new JacksonFactory.JSON().newWriter(locationInfo, properties, compact), charset, compact, complete, eventEol);
+ protected JsonLayout(final boolean locationInfo, final boolean properties, final boolean complete,
+ final boolean compact, final boolean eventEol, final Charset charset) {
+ super(new JacksonFactory.JSON().newWriter(locationInfo, properties, compact), charset, compact, complete,
+ eventEol);
}
/**
@@ -851,18 +856,18 @@ public final class JsonLayout extends AbstractJacksonLayout {
* Creates a JSON Layout.
*
* @param locationInfo
- * If "true", includes the location information in the generated JSON.
+ * If "true", includes the location information in the generated JSON.
* @param properties
- * If "true", includes the thread context in the generated JSON.
+ * If "true", includes the thread context in the generated JSON.
* @param complete
- * If "true", includes the JSON header and footer, defaults to "false".
+ * If "true", includes the JSON header and footer, defaults to "false".
* @param compact
- * If "true", does not use end-of-lines and indentation, defaults to "false".
+ * If "true", does not use end-of-lines and indentation, defaults to "false".
* @param eventEol
- * If "true", forces an EOL after each log event (even if compact is "true"), defaults to "false". This
- * allows one even per line, even in compact mode.
+ * If "true", forces an EOL after each log event (even if compact is "true"), defaults to "false". This
+ * allows one even per line, even in compact mode.
* @param charset
- * The character set to use, if {@code null}, uses "UTF-8".
+ * The character set to use, if {@code null}, uses "UTF-8".
* @return A JSON Layout.
*/
@PluginFactory
@@ -887,4 +892,12 @@ public final class JsonLayout extends AbstractJacksonLayout {
public static AbstractJacksonLayout createDefaultLayout() {
return new JsonLayout(false, false, false, false, false, StandardCharsets.UTF_8);
}
+
+ @Override
+ public void toSerializable(final LogEvent event, Writer writer) throws IOException {
+ if (complete && eventCount > 1) {
+ writer.append(", ");
+ }
+ super.toSerializable(event, writer);
+ }
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7da92dee/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 070596d..cd9ca6f 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -28,6 +28,9 @@
Added option to discard events below a certain log level if the async logger ring buffer
or async appender queue remaining capacity falls below a certain ratio.
</action>
+ <action issue="LOG4J2-908" dev="ggregory" type="fix" due-to="Konstantinos Liakos, Patrick Flaherty, Robin Coe, Gary Gregory">
+ JSONLayout doesn't add a comma between log events.
+ </action>
<action issue="LOG4J2-1212" dev="rpopma" type="fix">
Fix documentation to correctly specify the blocking wait strategy as the default for async loggers.
</action>
[42/50] logging-log4j2 git commit: [LOG4J2-1192] Dynamic Subject for
SMTP Appender.
Posted by mi...@apache.org.
[LOG4J2-1192] Dynamic Subject for SMTP Appender.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/711278b4
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/711278b4
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/711278b4
Branch: refs/heads/LOG4J-1181
Commit: 711278b4460fb68f192c2ee562b6b238f4c131a1
Parents: 5656ffd
Author: ggregory <gg...@apache.org>
Authored: Mon Jan 4 15:12:00 2016 -0800
Committer: ggregory <gg...@apache.org>
Committed: Mon Jan 4 15:12:00 2016 -0800
----------------------------------------------------------------------
.../log4j/core/appender/SmtpAppender.java | 7 ++-
.../log4j/core/layout/PatternLayout.java | 29 +++++++++++-
.../logging/log4j/core/net/SmtpManager.java | 49 +++++++++++---------
.../log4j/core/appender/SmtpAppenderTest.java | 17 ++++---
src/changes/changes.xml | 3 ++
5 files changed, 72 insertions(+), 33 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/711278b4/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/SmtpAppender.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/SmtpAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/SmtpAppender.java
index 10668af..28edd24 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/SmtpAppender.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/SmtpAppender.java
@@ -22,8 +22,11 @@ import java.io.Serializable;
import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.Layout;
import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.DefaultConfiguration;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
import org.apache.logging.log4j.core.config.plugins.PluginElement;
import org.apache.logging.log4j.core.config.plugins.PluginFactory;
import org.apache.logging.log4j.core.filter.ThresholdFilter;
@@ -105,6 +108,7 @@ public final class SmtpAppender extends AbstractAppender {
*/
@PluginFactory
public static SmtpAppender createAppender(
+ @PluginConfiguration final Configuration config,
@PluginAttribute("name") final String name,
@PluginAttribute("to") final String to,
@PluginAttribute("cc") final String cc,
@@ -138,8 +142,9 @@ public final class SmtpAppender extends AbstractAppender {
if (filter == null) {
filter = ThresholdFilter.createFilter(null, null, null);
}
+ final Configuration configuration = config != null ? config : new DefaultConfiguration();
- final SmtpManager manager = SmtpManager.getSMTPManager(to, cc, bcc, from, replyTo, subject, smtpProtocol,
+ final SmtpManager manager = SmtpManager.getSmtpManager(configuration, to, cc, bcc, from, replyTo, subject, smtpProtocol,
smtpHost, smtpPort, smtpUsername, smtpPassword, isSmtpDebug, filter.toString(), bufferSize);
if (manager == null) {
return null;
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/711278b4/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java
index 4f9244d..0503fc8 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java
@@ -17,6 +17,7 @@
package org.apache.logging.log4j.core.layout;
import java.nio.charset.Charset;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -127,7 +128,7 @@ public final class PatternLayout extends AbstractStringLayout {
alwaysWriteExceptions, noConsoleNoAnsi);
}
- private Serializer createSerializer(final Configuration configuration, final RegexReplacement replace,
+ public static Serializer createSerializer(final Configuration configuration, final RegexReplacement replace,
final String pattern, final String defaultPattern, final PatternSelector patternSelector,
final boolean alwaysWriteExceptions, final boolean noConsoleNoAnsi) {
if (Strings.isEmpty(pattern) && Strings.isEmpty(defaultPattern)) {
@@ -278,7 +279,7 @@ public final class PatternLayout extends AbstractStringLayout {
.build();
}
- private interface Serializer {
+ public interface Serializer {
String toSerializable(final LogEvent event);
}
@@ -307,6 +308,18 @@ public final class PatternLayout extends AbstractStringLayout {
}
return str;
}
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append(super.toString());
+ builder.append("[formatters=");
+ builder.append(Arrays.toString(formatters));
+ builder.append(", replace=");
+ builder.append(replace);
+ builder.append("]");
+ return builder.toString();
+ }
}
private static class PatternSelectorSerializer implements Serializer {
@@ -334,6 +347,18 @@ public final class PatternLayout extends AbstractStringLayout {
}
return str;
}
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append(super.toString());
+ builder.append("[patternSelector=");
+ builder.append(patternSelector);
+ builder.append(", replace=");
+ builder.append(replace);
+ builder.append("]");
+ return builder.toString();
+ }
}
/**
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/711278b4/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SmtpManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SmtpManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SmtpManager.java
index 7727457..67f0932 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SmtpManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SmtpManager.java
@@ -41,6 +41,11 @@ import org.apache.logging.log4j.core.Layout;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractManager;
import org.apache.logging.log4j.core.appender.ManagerFactory;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.DefaultConfiguration;
+import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
+import org.apache.logging.log4j.core.layout.PatternLayout;
+import org.apache.logging.log4j.core.layout.PatternLayout.Serializer;
import org.apache.logging.log4j.core.util.CyclicBuffer;
import org.apache.logging.log4j.core.util.NameUtil;
import org.apache.logging.log4j.core.util.NetUtils;
@@ -54,13 +59,21 @@ public class SmtpManager extends AbstractManager {
private static final SMTPManagerFactory FACTORY = new SMTPManagerFactory();
private final Session session;
-
+
private final CyclicBuffer<LogEvent> buffer;
private volatile MimeMessage message;
private final FactoryData data;
+ private static MimeMessage createMimeMessage(final FactoryData data, final Session session, LogEvent appendEvent)
+ throws MessagingException {
+ return new MimeMessageBuilder(session).setFrom(data.from).setReplyTo(data.replyto)
+ .setRecipients(Message.RecipientType.TO, data.to).setRecipients(Message.RecipientType.CC, data.cc)
+ .setRecipients(Message.RecipientType.BCC, data.bcc).setSubject(data.subject.toSerializable(appendEvent))
+ .getMimeMessage();
+ }
+
protected SmtpManager(final String name, final Session session, final MimeMessage message,
final FactoryData data) {
super(name);
@@ -74,7 +87,9 @@ public class SmtpManager extends AbstractManager {
buffer.add(event);
}
- public static SmtpManager getSMTPManager(final String to, final String cc, final String bcc,
+ public static SmtpManager getSmtpManager(
+ final Configuration config,
+ final String to, final String cc, final String bcc,
final String from, final String replyTo,
final String subject, String protocol, final String host,
final int port, final String username, final String password,
@@ -120,8 +135,9 @@ public class SmtpManager extends AbstractManager {
sb.append(filterName);
final String name = "SMTP:" + NameUtil.md5(sb.toString());
+ final Serializer subjectSerializer = PatternLayout.createSerializer(config, null, subject, null, null, false, false);
- return getManager(name, FACTORY, new FactoryData(to, cc, bcc, from, replyTo, subject,
+ return getManager(name, FACTORY, new FactoryData(to, cc, bcc, from, replyTo, subjectSerializer,
protocol, host, port, username, password, isDebug, numElements));
}
@@ -132,7 +148,7 @@ public class SmtpManager extends AbstractManager {
*/
public void sendEvents(final Layout<?> layout, final LogEvent appendEvent) {
if (message == null) {
- connect();
+ connect(appendEvent);
}
try {
final LogEvent[] priorEvents = buffer.removeAll();
@@ -251,7 +267,7 @@ public class SmtpManager extends AbstractManager {
private final String bcc;
private final String from;
private final String replyto;
- private final String subject;
+ private final Serializer subject;
private final String protocol;
private final String host;
private final int port;
@@ -261,14 +277,14 @@ public class SmtpManager extends AbstractManager {
private final int numElements;
public FactoryData(final String to, final String cc, final String bcc, final String from, final String replyTo,
- final String subject, final String protocol, final String host, final int port,
+ final Serializer subjectSerializer, final String protocol, final String host, final int port,
final String username, final String password, final boolean isDebug, final int numElements) {
this.to = to;
this.cc = cc;
this.bcc = bcc;
this.from = from;
this.replyto = replyTo;
- this.subject = subject;
+ this.subject = subjectSerializer;
this.protocol = protocol;
this.host = host;
this.port = port;
@@ -279,14 +295,12 @@ public class SmtpManager extends AbstractManager {
}
}
- private synchronized void connect() {
+ private synchronized void connect(LogEvent appendEvent) {
if (message != null) {
return;
}
try {
- message = new MimeMessageBuilder(session).setFrom(data.from).setReplyTo(data.replyto)
- .setRecipients(Message.RecipientType.TO, data.to).setRecipients(Message.RecipientType.CC, data.cc)
- .setRecipients(Message.RecipientType.BCC, data.bcc).setSubject(data.subject).getMimeMessage();
+ message = createMimeMessage(data, session, appendEvent);
} catch (final MessagingException e) {
logError("Could not set SmtpAppender message options", e);
message = null;
@@ -324,18 +338,7 @@ public class SmtpManager extends AbstractManager {
final Session session = Session.getInstance(properties, authenticator);
session.setProtocolForAddress("rfc822", data.protocol);
session.setDebug(data.isDebug);
- MimeMessage message;
-
- try {
- message = new MimeMessageBuilder(session).setFrom(data.from).setReplyTo(data.replyto)
- .setRecipients(Message.RecipientType.TO, data.to).setRecipients(Message.RecipientType.CC, data.cc)
- .setRecipients(Message.RecipientType.BCC, data.bcc).setSubject(data.subject).getMimeMessage();
- } catch (final MessagingException e) {
- LOGGER.error("Could not set SmtpAppender message options.", e);
- message = null;
- }
-
- return new SmtpManager(name, session, message, data);
+ return new SmtpManager(name, session, null, data);
}
private Authenticator buildAuthenticator(final String username, final String password) {
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/711278b4/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SmtpAppenderTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SmtpAppenderTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SmtpAppenderTest.java
index f433a40..b0577ee 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SmtpAppenderTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SmtpAppenderTest.java
@@ -26,6 +26,7 @@ import javax.mail.internet.InternetAddress;
import org.apache.logging.dumbster.smtp.SimpleSmtpServer;
import org.apache.logging.dumbster.smtp.SmtpMessage;
import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.ThreadContext;
import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.net.MimeMessageBuilder;
@@ -130,10 +131,12 @@ public class SmtpAppenderTest {
@Test
public void testDelivery() {
- final SmtpAppender appender = SmtpAppender.createAppender("Test",
- "to@example.com", "cc@example.com", "bcc@example.com",
- "from@example.com", "replyTo@example.com", "Subject", null,
- HOST, PORT, null, null, "false", "3", null, null, "true");
+ final String subjectKey = getClass().getName();
+ final String subjectValue = "SubjectValue1";
+ ThreadContext.put(subjectKey, subjectValue);
+ final SmtpAppender appender = SmtpAppender.createAppender(null, "Test", "to@example.com", "cc@example.com",
+ "bcc@example.com", "from@example.com", "replyTo@example.com", "Subject Pattern %X{" + subjectKey + "}",
+ null, HOST, PORT, null, null, "false", "3", null, null, "true");
appender.start();
final LoggerContext context = LoggerContext.getContext();
@@ -148,8 +151,7 @@ public class SmtpAppenderTest {
root.debug("Debug message #2");
root.debug("Debug message #3");
root.debug("Debug message #4");
- root.error("Error with exception", new RuntimeException(
- "Exception message"));
+ root.error("Error with exception", new RuntimeException("Exception message"));
root.error("Error message #2");
server.stop();
@@ -163,7 +165,8 @@ public class SmtpAppenderTest {
// can't be tested with Dumpster 1.6
assertEquals("from@example.com", email.getHeaderValue("From"));
assertEquals("replyTo@example.com", email.getHeaderValue("Reply-To"));
- assertEquals("Subject", email.getHeaderValue("Subject"));
+ final String headerValue = email.getHeaderValue("Subject");
+ assertEquals(headerValue, "Subject Pattern " + subjectValue);
final String body = email.getBody();
assertFalse(body.contains("Debug message #1"));
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/711278b4/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 6c36be1..0664458 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -31,6 +31,9 @@
<action issue="LOG4J2-1237" dev="ggregory" type="add" due-to="Mike Calmus, Gary Gregory">
Make PatternLayout header and footer accept a pattern.
</action>
+ <action issue="LOG4J2-1192" dev="ggregory" type="add" due-to="Jörg Bretschneider, Gary Gregory">
+ Dynamic Subject for SMTP Appender.
+ </action>
<action issue="LOG4J2-908" dev="ggregory" type="fix" due-to="Konstantinos Liakos, Patrick Flaherty, Robin Coe, Gary Gregory">
JSONLayout doesn't add a comma between log events.
</action>
[45/50] logging-log4j2 git commit: LOG4J2-1248 Fixed broken nanotime
in pattern layout
Posted by mi...@apache.org.
LOG4J2-1248 Fixed broken nanotime in pattern layout
- removed NanoClockFactory (which essentially served as a global variable)
- Configuration now has nanoClock accessors
- AbstractConfiguration now has a nanoClock field with a DummyNanoClock as initial value
- PatternParser sets its Configuration's nanoClock when it detects a nanotime conversion pattern
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/d6b7f483
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/d6b7f483
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/d6b7f483
Branch: refs/heads/LOG4J-1181
Commit: d6b7f4832a3562d615b7f251aff7c3d51107c0c2
Parents: 75d33d9
Author: rpopma <rp...@apache.org>
Authored: Sat Jan 9 15:58:07 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sat Jan 9 15:58:07 2016 +0900
----------------------------------------------------------------------
.../logging/log4j/core/LoggerContext.java | 51 ++++++------
.../logging/log4j/core/async/AsyncLogger.java | 5 +-
.../core/config/AbstractConfiguration.java | 57 +++++++------
.../log4j/core/config/Configuration.java | 28 +++++--
.../log4j/core/pattern/PatternParser.java | 15 ++--
.../log4j/core/util/NanoClockFactory.java | 84 --------------------
.../core/async/AsyncLoggerTestNanoTime.java | 15 ++--
.../log4j/core/pattern/PatternParserTest.java | 53 +++++++-----
.../log4j/core/util/NanoClockFactoryTest.java | 65 ---------------
src/changes/changes.xml | 13 +--
10 files changed, 140 insertions(+), 246 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d6b7f483/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
index f2ae53b..42efbb5 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
@@ -39,7 +39,6 @@ import org.apache.logging.log4j.core.config.Reconfigurable;
import org.apache.logging.log4j.core.impl.Log4jLogEvent;
import org.apache.logging.log4j.core.jmx.Server;
import org.apache.logging.log4j.core.util.Cancellable;
-import org.apache.logging.log4j.core.util.NanoClockFactory;
import org.apache.logging.log4j.core.util.NetUtils;
import org.apache.logging.log4j.core.util.ShutdownCallbackRegistry;
import org.apache.logging.log4j.message.MessageFactory;
@@ -82,7 +81,7 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi
/**
* Constructor taking only a name.
- *
+ *
* @param name The context name.
*/
public LoggerContext(final String name) {
@@ -91,7 +90,7 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi
/**
* Constructor taking a name and a reference to an external context.
- *
+ *
* @param name The context name.
* @param externalContext The external context.
*/
@@ -101,7 +100,7 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi
/**
* Constructor taking a name, external context and a configuration URI.
- *
+ *
* @param name The context name.
* @param externalContext The external context.
* @param configLocn The location of the configuration as a URI.
@@ -150,7 +149,7 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi
* WARNING - The LoggerContext returned by this method may not be the LoggerContext used to create a Logger for the
* calling class.
* </p>
- *
+ *
* @return The current LoggerContext.
* @see LogManager#getContext()
*/
@@ -226,7 +225,7 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi
/**
* Starts with a specific configuration.
- *
+ *
* @param config The new Configuration.
*/
public void start(final Configuration config) {
@@ -318,19 +317,19 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi
public String getName() {
return contextName;
}
-
+
/**
* Gets the root logger.
- *
+ *
* @return the root logger.
*/
public Logger getRootLogger() {
return getLogger(LogManager.ROOT_LOGGER_NAME);
}
-
+
/**
* Sets the name.
- *
+ *
* @param name the new LoggerContext name
* @throws NullPointerException if the specified name is {@code null}
*/
@@ -340,7 +339,7 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi
/**
* Sets the external context.
- *
+ *
* @param context The external context.
*/
public void setExternalContext(final Object context) {
@@ -349,7 +348,7 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi
/**
* Returns the external context.
- *
+ *
* @return The external context.
*/
@Override
@@ -359,7 +358,7 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi
/**
* Gets a Logger from the Context.
- *
+ *
* @param name The name of the Logger to return.
* @return The Logger.
*/
@@ -383,7 +382,7 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi
/**
* Obtains a Logger from the Context.
- *
+ *
* @param name The name of the Logger to return.
* @param messageFactory The message factory is used only when creating a logger, subsequent use does not change the
* logger but will log a warning if mismatched.
@@ -391,7 +390,7 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi
*/
@Override
public Logger getLogger(final String name, final MessageFactory messageFactory) {
- // Note: This is the only method where we add entries to the 'loggers' ivar.
+ // Note: This is the only method where we add entries to the 'loggers' ivar.
// The loggers map key is the logger name plus the messageFactory FQCN.
String key = LoggerContextKey.create(name, messageFactory);
Logger logger = loggers.get(key);
@@ -409,7 +408,7 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi
/**
* Determines if the specified Logger exists.
- *
+ *
* @param name The Logger name to search for.
* @return True if the Logger exists, false otherwise.
*/
@@ -420,7 +419,7 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi
/**
* Determines if the specified Logger exists.
- *
+ *
* @param name The Logger name to search for.
* @return True if the Logger exists, false otherwise.
*/
@@ -431,7 +430,7 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi
/**
* Determines if the specified Logger exists.
- *
+ *
* @param name The Logger name to search for.
* @return True if the Logger exists, false otherwise.
*/
@@ -452,7 +451,7 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi
/**
* Adds a Filter to the Configuration. Filters that are added through the API will be lost when a reconfigure
* occurs.
- *
+ *
* @param filter The Filter to add.
*/
public void addFilter(final Filter filter) {
@@ -461,7 +460,7 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi
/**
* Removes a Filter from the current Configuration.
- *
+ *
* @param filter The Filter to remove.
*/
public void removeFilter(final Filter filter) {
@@ -470,7 +469,7 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi
/**
* Sets the Configuration to be used.
- *
+ *
* @param config The new Configuration.
* @return The previous Configuration.
*/
@@ -506,8 +505,8 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi
LOGGER.error("Could not reconfigure JMX", t);
}
// AsyncLoggers update their nanoClock when the configuration changes
- Log4jLogEvent.setNanoClock(NanoClockFactory.createNanoClock());
-
+ Log4jLogEvent.setNanoClock(configuration.getNanoClock());
+
return prev;
} finally {
configLock.unlock();
@@ -533,7 +532,7 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi
* current configuration. Use {@link #getConfiguration()}.{@link Configuration#getConfigurationSource()
* getConfigurationSource()}.{@link ConfigurationSource#getLocation() getLocation()} to get the actual source of the
* current configuration.
- *
+ *
* @return the initial configuration location or {@code null}
*/
public URI getConfigLocation() {
@@ -542,7 +541,7 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi
/**
* Sets the configLocation to the specified value and reconfigures this context.
- *
+ *
* @param configLocation the location of the new configuration
*/
public void setConfigLocation(final URI configLocation) {
@@ -587,7 +586,7 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi
/**
* Causes all Logger to be updated against the specified Configuration.
- *
+ *
* @param config The Configuration.
*/
public void updateLoggers(final Configuration config) {
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d6b7f483/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLogger.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLogger.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLogger.java
index 62a2bba..048f04d 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLogger.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLogger.java
@@ -32,7 +32,6 @@ import org.apache.logging.log4j.core.util.Clock;
import org.apache.logging.log4j.core.util.ClockFactory;
import org.apache.logging.log4j.core.util.Constants;
import org.apache.logging.log4j.core.util.NanoClock;
-import org.apache.logging.log4j.core.util.NanoClockFactory;
import org.apache.logging.log4j.message.Message;
import org.apache.logging.log4j.message.MessageFactory;
import org.apache.logging.log4j.message.TimestampMessage;
@@ -89,7 +88,7 @@ public class AsyncLogger extends Logger implements EventTranslatorVararg<RingBuf
final AsyncLoggerDisruptor loggerDisruptor) {
super(context, name, messageFactory);
this.loggerDisruptor = loggerDisruptor;
- nanoClock = NanoClockFactory.createNanoClock(); // based on initial configuration
+ nanoClock = context.getConfiguration().getNanoClock();
}
/*
@@ -100,7 +99,7 @@ public class AsyncLogger extends Logger implements EventTranslatorVararg<RingBuf
@Override
protected void updateConfiguration(Configuration newConfig) {
super.updateConfiguration(newConfig);
- nanoClock = NanoClockFactory.createNanoClock();
+ nanoClock = newConfig.getNanoClock();
LOGGER.trace("[{}] AsyncLogger {} uses {}.", getContext().getName(), getName(), nanoClock);
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d6b7f483/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
index 8834db6..c9769e0 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
@@ -40,8 +40,10 @@ import org.apache.logging.log4j.core.script.AbstractScript;
import org.apache.logging.log4j.core.script.ScriptManager;
import org.apache.logging.log4j.core.script.ScriptRef;
import org.apache.logging.log4j.core.util.Constants;
+import org.apache.logging.log4j.core.util.DummyNanoClock;
import org.apache.logging.log4j.core.util.Loader;
import org.apache.logging.log4j.core.util.NameUtil;
+import org.apache.logging.log4j.core.util.NanoClock;
import org.apache.logging.log4j.core.util.WatchManager;
import org.apache.logging.log4j.util.PropertiesUtil;
@@ -86,7 +88,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
* Packages found in configuration "packages" attribute.
*/
protected final List<String> pluginPackages = new ArrayList<>();
-
+
/**
* The plugin manager.
*/
@@ -117,7 +119,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
private ConfigurationScheduler configurationScheduler = new ConfigurationScheduler();
private final WatchManager watchManager = new WatchManager(configurationScheduler);
private AsyncLoggerConfigDisruptor asyncLoggerConfigDisruptor;
-
+ private NanoClock nanoClock = new DummyNanoClock();
/**
* Constructor.
@@ -268,11 +270,11 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
loggerConfig.getReliabilityStrategy().beforeStopConfiguration(this);
}
root.getReliabilityStrategy().beforeStopConfiguration(this);
-
+
final String cls = getClass().getSimpleName();
LOGGER.trace("{} notified {} ReliabilityStrategies that config will be stopped.", cls, loggerConfigs.size()
+ 1);
-
+
if (!loggerConfigs.isEmpty()) {
LOGGER.trace("{} stopping {} LoggerConfigs.", cls, loggerConfigs.size());
for (final LoggerConfig logger : loggerConfigs.values()) {
@@ -288,7 +290,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
LOGGER.trace("{} stopping AsyncLoggerConfigDisruptor.", cls);
asyncLoggerConfigDisruptor.stop();
}
-
+
// Stop the appenders in reverse order in case they still have activity.
final Appender[] array = appenders.values().toArray(new Appender[appenders.size()]);
final List<Appender> async = getAsyncAppenders(array);
@@ -305,7 +307,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
loggerConfig.getReliabilityStrategy().beforeStopAppenders();
}
root.getReliabilityStrategy().beforeStopAppenders();
-
+
LOGGER.trace("{} stopping remaining Appenders.", cls);
int appenderCount = 0;
for (int i = array.length - 1; i >= 0; --i) {
@@ -339,7 +341,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
}
LOGGER.debug("Stopped {} OK", this);
}
-
+
private List<Appender> getAsyncAppenders(final Appender[] all) {
final List<Appender> result = new ArrayList<Appender>();
for (int i = all.length - 1; i >= 0; --i) {
@@ -534,7 +536,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
/**
* Set the name of the configuration.
- *
+ *
* @param name The name.
*/
public void setName(final String name) {
@@ -543,7 +545,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
/**
* Returns the name of the configuration.
- *
+ *
* @return the name of the configuration.
*/
@Override
@@ -553,7 +555,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
/**
* Add a listener for changes on the configuration.
- *
+ *
* @param listener The ConfigurationListener to add.
*/
@Override
@@ -563,7 +565,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
/**
* Remove a ConfigurationListener.
- *
+ *
* @param listener The ConfigurationListener to remove.
*/
@Override
@@ -573,7 +575,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
/**
* Returns the Appender with the specified name.
- *
+ *
* @param appenderName The name of the Appender.
* @return the Appender with the specified name or null if the Appender cannot be located.
*/
@@ -585,7 +587,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
/**
* Returns a Map containing all the Appenders and their name.
- *
+ *
* @return A Map containing each Appender's name and the Appender object.
*/
@Override
@@ -595,7 +597,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
/**
* Adds an Appender to the configuration.
- *
+ *
* @param appender The Appender to add.
*/
@Override
@@ -634,7 +636,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
* being updated at the same time.
*
* Note: This method is not used when configuring via configuration. It is primarily used by unit tests.
- *
+ *
* @param logger The Logger the Appender will be associated with.
* @param appender The Appender.
*/
@@ -661,7 +663,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
* updated at the same time.
*
* Note: This method is not used when configuring via configuration. It is primarily used by unit tests.
- *
+ *
* @param logger The Logger the Footer will be associated with.
* @param filter The Filter.
*/
@@ -686,7 +688,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
* updated at the same time.
*
* Note: This method is not used when configuring via configuration. It is primarily used by unit tests.
- *
+ *
* @param logger The Logger the Appender will be associated with.
* @param additive True if the LoggerConfig should be additive, false otherwise.
*/
@@ -709,7 +711,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
* Remove an Appender. First removes any associations between LoggerConfigs and the Appender, removes the Appender
* from this appender list and then stops the appender. This method is synchronized in case an Appender with the
* same name is being added during the removal.
- *
+ *
* @param appenderName the name of the appender to remove.
*/
public synchronized void removeAppender(final String appenderName) {
@@ -725,7 +727,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
/*
* (non-Javadoc)
- *
+ *
* @see org.apache.logging.log4j.core.config.Configuration#getCustomLevels()
*/
@Override
@@ -736,7 +738,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
/**
* Locates the appropriate LoggerConfig for a Logger name. This will remove tokens from the package name as
* necessary or return the root LoggerConfig if no other matches were found.
- *
+ *
* @param loggerName The Logger name.
* @return The located LoggerConfig.
*/
@@ -758,7 +760,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
/**
* Returns the root Logger.
- *
+ *
* @return the root Logger.
*/
@Override
@@ -768,7 +770,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
/**
* Returns a Map of all the LoggerConfigs.
- *
+ *
* @return a Map with each entry containing the name of the Logger and the LoggerConfig.
*/
@Override
@@ -778,7 +780,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
/**
* Returns the LoggerConfig with the specified name.
- *
+ *
* @param loggerName The Logger name.
* @return The LoggerConfig or null if no match was found.
*/
@@ -948,4 +950,13 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
return buffer.toByteArray();
}
+ @Override
+ public NanoClock getNanoClock() {
+ return nanoClock;
+ }
+
+ @Override
+ public void setNanoClock(final NanoClock nanoClock) {
+ this.nanoClock = Objects.requireNonNull(nanoClock, "nanoClock");
+ }
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d6b7f483/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configuration.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configuration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configuration.java
index e9bb6a0..900566d 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configuration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configuration.java
@@ -29,6 +29,7 @@ import org.apache.logging.log4j.core.filter.Filterable;
import org.apache.logging.log4j.core.lookup.StrSubstitutor;
import org.apache.logging.log4j.core.net.Advertiser;
import org.apache.logging.log4j.core.script.ScriptManager;
+import org.apache.logging.log4j.core.util.NanoClock;
import org.apache.logging.log4j.core.util.WatchManager;
/**
@@ -41,7 +42,7 @@ public interface Configuration extends Filterable {
/**
* Returns the configuration name.
- *
+ *
* @return the name of the configuration.
*/
String getName();
@@ -49,7 +50,7 @@ public interface Configuration extends Filterable {
/**
* Locates the appropriate LoggerConfig for a Logger name. This will remove tokens from the package name as
* necessary or return the root LoggerConfig if no other matches were found.
- *
+ *
* @param name The Logger name.
* @return The located LoggerConfig.
*/
@@ -57,7 +58,7 @@ public interface Configuration extends Filterable {
/**
* Returns the Appender with the specified name.
- *
+ *
* @param <T> The expected Appender type.
* @param name The name of the Appender.
* @return the Appender with the specified name or null if the Appender cannot be located.
@@ -66,7 +67,7 @@ public interface Configuration extends Filterable {
/**
* Returns a Map containing all the Appenders and their name.
- *
+ *
* @return A Map containing each Appender's name and the Appender object.
*/
Map<String, Appender> getAppenders();
@@ -123,7 +124,7 @@ public interface Configuration extends Filterable {
/**
* Returns the source of this configuration.
- *
+ *
* @return the source of this configuration
*/
ConfigurationSource getConfigurationSource();
@@ -141,7 +142,7 @@ public interface Configuration extends Filterable {
* {@link Level#getLevel(String)}), it is just not in the current configuration. {@link Level#values()} will return
* {A, B, C, D and the built-in levels}.
* </p>
- *
+ *
* @return the custom levels defined in the current configuration
*/
List<CustomLevelConfig> getCustomLevels();
@@ -151,7 +152,7 @@ public interface Configuration extends Filterable {
/**
* Returns the {@code AsyncLoggerConfigDelegate} shared by all
* {@code AsyncLoggerConfig} instances defined in this Configuration.
- *
+ *
* @return the {@code AsyncLoggerConfigDelegate}
*/
AsyncLoggerConfigDelegate getAsyncLoggerConfigDelegate();
@@ -172,4 +173,17 @@ public interface Configuration extends Filterable {
ReliabilityStrategy getReliabilityStrategy(LoggerConfig loggerConfig);
+ /**
+ * Returns the {@link NanoClock} instance for this configuration.
+ *
+ * @return the nano clock
+ */
+ NanoClock getNanoClock();
+
+ /**
+ * Sets the {@link NanoClock} instance for this configuration.
+ *
+ * @param nanoClock the new nano clock for this configuration. Must be non-null.
+ */
+ void setNanoClock(NanoClock nanoClock);
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d6b7f483/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java
index 08b66db..4adb90a 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java
@@ -29,7 +29,7 @@ import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.plugins.util.PluginManager;
import org.apache.logging.log4j.core.config.plugins.util.PluginType;
-import org.apache.logging.log4j.core.util.NanoClockFactory;
+import org.apache.logging.log4j.core.util.SystemNanoClock;
import org.apache.logging.log4j.status.StatusLogger;
import org.apache.logging.log4j.util.Strings;
@@ -173,12 +173,13 @@ public final class PatternParser {
final Iterator<FormattingInfo> fieldIter = fields.iterator();
boolean handlesThrowable = false;
- NanoClockFactory.setMode(NanoClockFactory.Mode.Dummy); // LOG4J2-1074 use dummy clock by default
for (final PatternConverter converter : converters) {
if (converter instanceof NanoTimePatternConverter) {
// LOG4J2-1074 Switch to actual clock if nanosecond timestamps are required in config.
- // LoggerContext will notify known NanoClockFactory users that the configuration has changed.
- NanoClockFactory.setMode(NanoClockFactory.Mode.System);
+ // LOG4J2-1248 set config nanoclock
+ if (config != null) {
+ config.setNanoClock(new SystemNanoClock());
+ }
}
LogEventPatternConverter pc;
if (converter instanceof LogEventPatternConverter) {
@@ -218,7 +219,7 @@ public final class PatternParser {
* last processed character.
* @param pattern
* format string.
- * @param i
+ * @param start
* current index into pattern format.
* @param convBuf
* buffer to receive conversion specifier.
@@ -256,7 +257,7 @@ public final class PatternParser {
*
* @param pattern
* conversion pattern.
- * @param i
+ * @param start
* start of options.
* @param options
* array to receive extracted options
@@ -567,7 +568,7 @@ public final class PatternParser {
* initial character of format specifier.
* @param pattern
* conversion pattern
- * @param i
+ * @param start
* current position in conversion pattern.
* @param currentLiteral
* current literal.
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d6b7f483/log4j-core/src/main/java/org/apache/logging/log4j/core/util/NanoClockFactory.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/NanoClockFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/NanoClockFactory.java
deleted file mode 100644
index 2a714ee..0000000
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/NanoClockFactory.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * 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.util;
-
-import java.util.Objects;
-
-/**
- * Creates the appropriate {@link NanoClock} instance for the current configuration.
- */
-public final class NanoClockFactory {
-
- /**
- * Enum over the different kinds of nano clocks this factory can create.
- */
- public static enum Mode {
- /**
- * Creates dummy nano clocks that always return a fixed value.
- */
- Dummy {
- @Override
- public NanoClock createNanoClock() {
- return new DummyNanoClock();
- }
- },
- /**
- * Creates real nano clocks which call {{System.nanoTime()}}.
- */
- System {
- @Override
- public NanoClock createNanoClock() {
- return new SystemNanoClock();
- }
- };
-
- public abstract NanoClock createNanoClock();
- }
-
- private static volatile Mode mode = Mode.Dummy;
-
- private NanoClockFactory() {
- }
-
- /**
- * Returns a new {@code NanoClock} determined by the mode of this factory.
- *
- * @return the appropriate {@code NanoClock} for the factory mode
- */
- public static NanoClock createNanoClock() {
- return mode.createNanoClock();
- }
-
- /**
- * Returns the factory mode.
- *
- * @return the factory mode that determines which kind of nano clocks this factory creates
- */
- public static Mode getMode() {
- return mode;
- }
-
- /**
- * Sets the factory mode.
- *
- * @param mode the factory mode that determines which kind of nano clocks this factory creates
- */
- public static void setMode(Mode mode) {
- NanoClockFactory.mode = Objects.requireNonNull(mode, "mode must be non-null");
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d6b7f483/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTestNanoTime.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTestNanoTime.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTestNanoTime.java
index bebb0ce..591d08b 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTestNanoTime.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTestNanoTime.java
@@ -26,8 +26,6 @@ import org.apache.logging.log4j.core.CoreLoggerContexts;
import org.apache.logging.log4j.core.config.ConfigurationFactory;
import org.apache.logging.log4j.core.util.Constants;
import org.apache.logging.log4j.core.util.DummyNanoClock;
-import org.apache.logging.log4j.core.util.NanoClockFactory;
-import org.apache.logging.log4j.core.util.NanoClockFactory.Mode;
import org.apache.logging.log4j.core.util.SystemNanoClock;
import org.apache.logging.log4j.util.Strings;
import org.junit.AfterClass;
@@ -61,15 +59,16 @@ public class AsyncLoggerTestNanoTime {
log.info("Use actual System.nanoTime()");
assertTrue("using SystemNanoClock", log.getNanoClock() instanceof SystemNanoClock);
- NanoClockFactory.setMode(Mode.Dummy);
- final long DUMMYNANOTIME = 0;
-
+ final long DUMMYNANOTIME = -53;
+ log.getContext().getConfiguration().setNanoClock(new DummyNanoClock(DUMMYNANOTIME));
+ log.updateConfiguration(log.getContext().getConfiguration());
+
// trigger a new nano clock lookup
log.updateConfiguration(log.getContext().getConfiguration());
-
+
log.info("Use dummy nano clock");
assertTrue("using SystemNanoClock", log.getNanoClock() instanceof DummyNanoClock);
-
+
CoreLoggerContexts.stopLoggerContext(file); // stop async thread
final BufferedReader reader = new BufferedReader(new FileReader(file));
@@ -87,7 +86,7 @@ public class AsyncLoggerTestNanoTime {
assertEquals(line1Parts[0], line1Parts[1]);
long loggedNanoTime = Long.parseLong(line1Parts[0]);
assertTrue("used system nano time", loggedNanoTime - before < TimeUnit.SECONDS.toNanos(1));
-
+
final String[] line2Parts = line2.split(" AND ");
assertEquals("Use dummy nano clock", line2Parts[2]);
assertEquals(String.valueOf(DUMMYNANOTIME), line2Parts[0]);
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d6b7f483/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/PatternParserTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/PatternParserTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/PatternParserTest.java
index d29eac8..f77eab7 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/PatternParserTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/PatternParserTest.java
@@ -26,9 +26,12 @@ import org.apache.logging.log4j.MarkerManager;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.NullConfiguration;
import org.apache.logging.log4j.core.impl.Log4jLogEvent;
import org.apache.logging.log4j.core.util.Constants;
-import org.apache.logging.log4j.core.util.NanoClockFactory;
+import org.apache.logging.log4j.core.util.DummyNanoClock;
+import org.apache.logging.log4j.core.util.SystemNanoClock;
import org.apache.logging.log4j.message.SimpleMessage;
import org.junit.Before;
import org.junit.Test;
@@ -111,7 +114,7 @@ public class PatternParserTest {
formatter.format(event, buf);
}
final String str = buf.toString();
- final String expected = "INFO [PatternParserTest :97 ] - Hello, world" + Constants.LINE_SEPARATOR;
+ final String expected = "INFO [PatternParserTest :100 ] - Hello, world" + Constants.LINE_SEPARATOR;
assertTrue("Expected to end with: " + expected + ". Actual: " + str, str.endsWith(expected));
}
@@ -157,14 +160,14 @@ public class PatternParserTest {
assertTrue("Expected to end with: " + expected + ". Actual: " + str, str.endsWith(expected));
}
-
+
@Test
public void testBadPattern() {
final Calendar cal = Calendar.getInstance();
cal.set(2001, Calendar.FEBRUARY, 3, 4, 5, 6);
cal.set(Calendar.MILLISECOND, 789);
final long timestamp = cal.getTimeInMillis();
-
+
final List<PatternFormatter> formatters = parser.parse(badPattern);
assertNotNull(formatters);
final Throwable t = new Throwable();
@@ -183,7 +186,7 @@ public class PatternParserTest {
formatter.format(event, buf);
}
final String str = buf.toString();
-
+
// eats all characters until the closing '}' character
final String expected = "[2001-02-03 04:05:06,789] - Hello, world";
assertTrue("Expected to start with: " + expected + ". Actual: " + str, str.startsWith(expected));
@@ -223,7 +226,7 @@ public class PatternParserTest {
assertTrue("Expected to start with: " + expectedStart + ". Actual: " + str, str.startsWith(expectedStart));
assertTrue("Expected to end with: \"" + expectedEnd + "\". Actual: \"" + str, str.endsWith(expectedEnd));
}
-
+
@Test
public void testNanoPatternShort() {
final List<PatternFormatter> formatters = parser.parse("%N");
@@ -231,7 +234,7 @@ public class PatternParserTest {
assertEquals(1, formatters.size());
assertTrue(formatters.get(0).getConverter() instanceof NanoTimePatternConverter);
}
-
+
@Test
public void testNanoPatternLong() {
final List<PatternFormatter> formatters = parser.parse("%nano");
@@ -239,20 +242,34 @@ public class PatternParserTest {
assertEquals(1, formatters.size());
assertTrue(formatters.get(0).getConverter() instanceof NanoTimePatternConverter);
}
-
+
@Test
- public void testNanoPatternShortChangesNanoClockFactoryMode() {
- parser.parse("%m");
- assertEquals(NanoClockFactory.Mode.Dummy, NanoClockFactory.getMode());
- parser.parse("%nano");
- assertEquals(NanoClockFactory.Mode.System, NanoClockFactory.getMode());
+ public void testNanoPatternShortChangesConfigurationNanoClock() {
+ Configuration config = new NullConfiguration();
+ assertTrue(config.getNanoClock() instanceof DummyNanoClock);
+
+ PatternParser pp = new PatternParser(config, KEY, null);
+ assertTrue(config.getNanoClock() instanceof DummyNanoClock);
+
+ pp.parse("%m");
+ assertTrue(config.getNanoClock() instanceof DummyNanoClock);
+
+ pp.parse("%nano"); // this changes the config clock
+ assertTrue(config.getNanoClock() instanceof SystemNanoClock);
}
-
+
@Test
public void testNanoPatternLongChangesNanoClockFactoryMode() {
- parser.parse("%m");
- assertEquals(NanoClockFactory.Mode.Dummy, NanoClockFactory.getMode());
- parser.parse("%N");
- assertEquals(NanoClockFactory.Mode.System, NanoClockFactory.getMode());
+ Configuration config = new NullConfiguration();
+ assertTrue(config.getNanoClock() instanceof DummyNanoClock);
+
+ PatternParser pp = new PatternParser(config, KEY, null);
+ assertTrue(config.getNanoClock() instanceof DummyNanoClock);
+
+ pp.parse("%m");
+ assertTrue(config.getNanoClock() instanceof DummyNanoClock);
+
+ pp.parse("%N");
+ assertTrue(config.getNanoClock() instanceof SystemNanoClock);
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d6b7f483/log4j-core/src/test/java/org/apache/logging/log4j/core/util/NanoClockFactoryTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/util/NanoClockFactoryTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/util/NanoClockFactoryTest.java
deleted file mode 100644
index f7667d6..0000000
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/util/NanoClockFactoryTest.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * 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.util;
-
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * Tests the NanoClockFactory.
- */
-public class NanoClockFactoryTest {
-
- @Test
- public void testDefaultModeIsDummy() {
- assertEquals(NanoClockFactory.Mode.Dummy, NanoClockFactory.getMode());
- }
-
- @Test
- public void testModeIsMutable() {
- assertEquals(NanoClockFactory.Mode.Dummy, NanoClockFactory.getMode());
- NanoClockFactory.setMode(NanoClockFactory.Mode.System);
- assertEquals(NanoClockFactory.Mode.System, NanoClockFactory.getMode());
-
- NanoClockFactory.setMode(NanoClockFactory.Mode.Dummy);
- assertEquals(NanoClockFactory.Mode.Dummy, NanoClockFactory.getMode());
- }
-
- @Test
- public void testModeDeterminesGeneratedClockType() {
- NanoClockFactory.setMode(NanoClockFactory.Mode.Dummy);
- assertEquals(NanoClockFactory.Mode.Dummy, NanoClockFactory.getMode());
- assertTrue("dummy", NanoClockFactory.createNanoClock() instanceof DummyNanoClock);
-
- NanoClockFactory.setMode(NanoClockFactory.Mode.System);
- assertEquals(NanoClockFactory.Mode.System, NanoClockFactory.getMode());
- assertTrue("system", NanoClockFactory.createNanoClock() instanceof SystemNanoClock);
-
- NanoClockFactory.setMode(NanoClockFactory.Mode.Dummy);
- assertEquals(NanoClockFactory.Mode.Dummy, NanoClockFactory.getMode());
- assertTrue("dummy again", NanoClockFactory.createNanoClock() instanceof DummyNanoClock);
-
- NanoClockFactory.setMode(NanoClockFactory.Mode.System);
- assertEquals(NanoClockFactory.Mode.System, NanoClockFactory.getMode());
- assertTrue("system", NanoClockFactory.createNanoClock() instanceof SystemNanoClock);
-
- NanoClockFactory.setMode(NanoClockFactory.Mode.Dummy);
- assertTrue("dummy again2", NanoClockFactory.createNanoClock() instanceof DummyNanoClock);
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d6b7f483/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index d6de059..b8fe598 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -24,19 +24,22 @@
</properties>
<body>
<release version="2.5.1" date="201Y-MM-DD" description="GA Release 2.5.1">
+ <action issue="LOG4J2-1248" dev="rpopma" type="fix">
+ Fixed broken nanotime in pattern layout.
+ </action>
<action issue="LOG4J2-1080" dev="rpopma" type="add">
Added option to discard events below a certain log level if the async logger ring buffer
or async appender queue remaining capacity falls below a certain ratio.
</action>
<action issue="LOG4J2-1237" dev="ggregory" type="add" due-to="Mike Calmus, Gary Gregory">
- Make PatternLayout header and footer accept a pattern.
+ Make PatternLayout header and footer accept a pattern.
</action>
<action issue="LOG4J2-1244" dev="ggregory" type="add" due-to="Anshu Garg, Remko Popma, Gary Gregory">
- Make header and footer values customizable in JSONLayout.
+ Make header and footer values customizable in JSONLayout.
</action>
<action issue="LOG4J2-1245" dev="ggregory" type="add">
- Make CSV Layout header and footers accept patterns.
- </action>
+ Make CSV Layout header and footers accept patterns.
+ </action>
<action issue="LOG4J2-1192" dev="ggregory" type="add" due-to="Jörg Bretschneider, Gary Gregory">
Dynamic Subject for SMTP Appender.
</action>
@@ -65,7 +68,7 @@
Update Liquibase from 3.3.5 to 3.4.2.
</action>
<action issue="LOG4J2-1233" dev="ggregory" type="update" due-to="Bahri Gencsoy">
- Misleading Value In Properties Example.
+ Misleading Value In Properties Example.
</action>
</release>
<release version="2.5" date="2015-12-06" description="GA Release 2.5">
[05/50] logging-log4j2 git commit: Link from ScriptFilter
documentation to the ScriptCondition docs for an example of embedding script
code directly in the configuration.
Posted by mi...@apache.org.
Link from ScriptFilter documentation to the ScriptCondition docs for an example of embedding script code directly in the configuration.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/1286d960
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/1286d960
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/1286d960
Branch: refs/heads/LOG4J-1181
Commit: 1286d960b02220717eea25050776b00e1253800b
Parents: 8c310be
Author: rpopma <rp...@apache.org>
Authored: Sun Dec 27 08:32:17 2015 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sun Dec 27 08:32:17 2015 +0900
----------------------------------------------------------------------
src/site/xdoc/manual/filters.xml | 2 ++
1 file changed, 2 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1286d960/src/site/xdoc/manual/filters.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/manual/filters.xml b/src/site/xdoc/manual/filters.xml
index 67f8059..f44ec10 100644
--- a/src/site/xdoc/manual/filters.xml
+++ b/src/site/xdoc/manual/filters.xml
@@ -550,6 +550,8 @@
</table>
<p>
The sample below shows how to declare script fields and then reference them in specific components.
+ See <a href="appenders.html#ScriptCondition">ScriptCondition</a> for an example of how the
+ <tt>Script</tt> element can be used to embed script code directly in the configuration.
</p>
<pre class="prettyprint linenums"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="ERROR">
[20/50] logging-log4j2 git commit: Update tests from Apache Active MQ
5.12.0 to 5.13.0.
Posted by mi...@apache.org.
Update tests from Apache Active MQ 5.12.0 to 5.13.0.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/680126bd
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/680126bd
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/680126bd
Branch: refs/heads/LOG4J-1181
Commit: 680126bdaf3eeb761e4393a7876f71ebf1f5e3d1
Parents: 39bf837
Author: ggregory <gg...@apache.org>
Authored: Wed Dec 30 23:03:05 2015 -0800
Committer: ggregory <gg...@apache.org>
Committed: Wed Dec 30 23:03:05 2015 -0800
----------------------------------------------------------------------
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/680126bd/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index ddec4d5..f6c89c8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -219,7 +219,7 @@
<projectDir />
<commonsLoggingVersion>1.2</commonsLoggingVersion>
<osgi.api.version>4.3.1</osgi.api.version>
- <activemq.version>5.12.0</activemq.version>
+ <activemq.version>5.13.0</activemq.version>
<!-- Allow Clirr severity to be overriden by the command-line option -DminSeverity=level -->
<minSeverity>info</minSeverity>
</properties>
[04/50] logging-log4j2 git commit: Ignore Eclipse project file.
Posted by mi...@apache.org.
Ignore Eclipse project file.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/7c5bb527
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/7c5bb527
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/7c5bb527
Branch: refs/heads/LOG4J-1181
Commit: 7c5bb527b7ccaf95e17058ea43340a4d766471fa
Parents: 8c310be
Author: ggregory <gg...@apache.org>
Authored: Fri Dec 25 07:12:39 2015 -0800
Committer: ggregory <gg...@apache.org>
Committed: Fri Dec 25 07:12:39 2015 -0800
----------------------------------------------------------------------
log4j-distribution/.gitignore | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7c5bb527/log4j-distribution/.gitignore
----------------------------------------------------------------------
diff --git a/log4j-distribution/.gitignore b/log4j-distribution/.gitignore
new file mode 100644
index 0000000..d8fe4fa
--- /dev/null
+++ b/log4j-distribution/.gitignore
@@ -0,0 +1 @@
+/.project
[24/50] logging-log4j2 git commit: [LOG4J2-1240] Update Liquibase
from 3.3.5 to 3.4.2.
Posted by mi...@apache.org.
[LOG4J2-1240] Update Liquibase from 3.3.5 to 3.4.2.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/d71e4cc9
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/d71e4cc9
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/d71e4cc9
Branch: refs/heads/LOG4J-1181
Commit: d71e4cc941e536ea333513d546f860d3c755da0b
Parents: 9fddd34
Author: ggregory <gg...@apache.org>
Authored: Wed Dec 30 23:29:41 2015 -0800
Committer: ggregory <gg...@apache.org>
Committed: Wed Dec 30 23:29:41 2015 -0800
----------------------------------------------------------------------
pom.xml | 4 ++--
src/changes/changes.xml | 3 +++
2 files changed, 5 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d71e4cc9/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index ce0e831..e2778af 100644
--- a/pom.xml
+++ b/pom.xml
@@ -492,7 +492,7 @@
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
- <version>1.1.1</version>
+ <version>1.2.1</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.jackson</groupId>
@@ -704,7 +704,7 @@
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
- <version>3.3.5</version>
+ <version>3.4.2</version>
</dependency>
<dependency>
<groupId>net.javacrumbs.json-unit</groupId>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d71e4cc9/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 8892b2b..a4b6798 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -46,6 +46,9 @@
<action issue="LOG4J2-1239" dev="ggregory" type="update">
Update Jackson from 2.6.3 to 2.6.4.
</action>
+ <action issue="LOG4J2-1240" dev="ggregory" type="update">
+ Update Liquibase from 3.3.5 to 3.4.2.
+ </action>
<action issue="LOG4J2-1233" dev="ggregory" type="update" due-to="Bahri Gencsoy">
Misleading Value In Properties Example.
</action>
[17/50] logging-log4j2 git commit: Log exceptions to status logger.
Posted by mi...@apache.org.
Log exceptions to status logger.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/24090006
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/24090006
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/24090006
Branch: refs/heads/LOG4J-1181
Commit: 24090006271cdcdd16a252c1fc708bfb68145885
Parents: 8b9962c
Author: ggregory <gg...@apache.org>
Authored: Wed Dec 30 17:12:25 2015 -0800
Committer: ggregory <gg...@apache.org>
Committed: Wed Dec 30 17:12:25 2015 -0800
----------------------------------------------------------------------
.../log4j/core/net/ssl/SslConfiguration.java | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/24090006/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SslConfiguration.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SslConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SslConfiguration.java
index 43464e5..a978f0b 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SslConfiguration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SslConfiguration.java
@@ -133,7 +133,7 @@ public class SslConfiguration {
try {
return SSLContext.getDefault();
} catch (final NoSuchAlgorithmException e) {
- LOGGER.error("Failed to create an SSLContext with default configuration");
+ LOGGER.error("Failed to create an SSLContext with default configuration", e);
return null;
}
}
@@ -158,11 +158,11 @@ public class SslConfiguration {
return newSslContext;
}
catch (final NoSuchAlgorithmException e) {
- LOGGER.error("No Provider supports a TrustManagerFactorySpi implementation for the specified protocol");
+ LOGGER.error("No Provider supports a TrustManagerFactorySpi implementation for the specified protocol", e);
throw new TrustStoreConfigurationException(e);
}
catch (final KeyManagementException e) {
- LOGGER.error("Failed to initialize the SSLContext");
+ LOGGER.error("Failed to initialize the SSLContext", e);
throw new KeyStoreConfigurationException(e);
}
}
@@ -176,10 +176,10 @@ public class SslConfiguration {
return trustStoreConfig.initTrustManagerFactory();
}
catch (final NoSuchAlgorithmException e) {
- LOGGER.error("The specified algorithm is not available from the specified provider");
+ LOGGER.error("The specified algorithm is not available from the specified provider", e);
throw new TrustStoreConfigurationException(e);
} catch (final KeyStoreException e) {
- LOGGER.error("Failed to initialize the TrustManagerFactory");
+ LOGGER.error("Failed to initialize the TrustManagerFactory", e);
throw new TrustStoreConfigurationException(e);
}
}
@@ -193,13 +193,13 @@ public class SslConfiguration {
return keyStoreConfig.initKeyManagerFactory();
}
catch (final NoSuchAlgorithmException e) {
- LOGGER.error("The specified algorithm is not available from the specified provider");
+ LOGGER.error("The specified algorithm is not available from the specified provider", e);
throw new KeyStoreConfigurationException(e);
} catch (final KeyStoreException e) {
- LOGGER.error("Failed to initialize the TrustManagerFactory");
+ LOGGER.error("Failed to initialize the TrustManagerFactory", e);
throw new KeyStoreConfigurationException(e);
} catch (final UnrecoverableKeyException e) {
- LOGGER.error("The key cannot be recovered (e.g. the given password is wrong)");
+ LOGGER.error("The key cannot be recovered (e.g. the given password is wrong)", e);
throw new KeyStoreConfigurationException(e);
}
}
[31/50] logging-log4j2 git commit: [LOG4J2-908] JSONLayout doesn't
add a comma between log events.
Posted by mi...@apache.org.
[LOG4J2-908] JSONLayout doesn't add a comma between log events.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/ca3fa309
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/ca3fa309
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/ca3fa309
Branch: refs/heads/LOG4J-1181
Commit: ca3fa309f51a982e5715528920c79fd8de871ae8
Parents: 27b3cb7
Author: ggregory <gg...@apache.org>
Authored: Sat Jan 2 17:34:06 2016 -0800
Committer: ggregory <gg...@apache.org>
Committed: Sat Jan 2 17:34:06 2016 -0800
----------------------------------------------------------------------
.../main/java/org/apache/logging/log4j/core/layout/JsonLayout.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ca3fa309/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java
index 0f1b618..e403731 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java
@@ -895,7 +895,7 @@ public final class JsonLayout extends AbstractJacksonLayout {
@Override
public void toSerializable(final LogEvent event, Writer writer) throws IOException {
- if (complete && eventCount > 1) {
+ if (complete && eventCount > 0) {
writer.append(", ");
}
super.toSerializable(event, writer);
[37/50] logging-log4j2 git commit: Fix typo in error message.
Posted by mi...@apache.org.
Fix typo in error message.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/dd079d10
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/dd079d10
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/dd079d10
Branch: refs/heads/LOG4J-1181
Commit: dd079d10f9f03bf510262d1e96cac04789749ce0
Parents: 235871e
Author: ggregory <gg...@apache.org>
Authored: Mon Jan 4 13:52:19 2016 -0800
Committer: ggregory <gg...@apache.org>
Committed: Mon Jan 4 13:52:19 2016 -0800
----------------------------------------------------------------------
.../main/java/org/apache/logging/log4j/core/net/SmtpManager.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/dd079d10/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SmtpManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SmtpManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SmtpManager.java
index 51d5f08..7727457 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SmtpManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SmtpManager.java
@@ -288,7 +288,7 @@ public class SmtpManager extends AbstractManager {
.setRecipients(Message.RecipientType.TO, data.to).setRecipients(Message.RecipientType.CC, data.cc)
.setRecipients(Message.RecipientType.BCC, data.bcc).setSubject(data.subject).getMimeMessage();
} catch (final MessagingException e) {
- logError("could not set SmtpAppender message options", e);
+ logError("Could not set SmtpAppender message options", e);
message = null;
}
}
[25/50] logging-log4j2 git commit: Add tests for LOG4J2-1232
Incorrect log rotation in last week of year.
Posted by mi...@apache.org.
Add tests for LOG4J2-1232
Incorrect log rotation in last week of year.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/d7efe9a1
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/d7efe9a1
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/d7efe9a1
Branch: refs/heads/LOG4J-1181
Commit: d7efe9a112ee1b2feeac66f54049d1f3a0368b71
Parents: d71e4cc
Author: ggregory <gg...@apache.org>
Authored: Thu Dec 31 18:46:08 2015 -0800
Committer: ggregory <gg...@apache.org>
Committed: Thu Dec 31 18:46:08 2015 -0800
----------------------------------------------------------------------
.../appender/rolling/PatternProcessorTest.java | 36 ++++++++++++++++++++
1 file changed, 36 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d7efe9a1/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessorTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessorTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessorTest.java
index 75b95a3..cebb0f4 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessorTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessorTest.java
@@ -22,6 +22,7 @@ import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
+import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.*;
@@ -51,6 +52,20 @@ public class PatternProcessorTest {
}
@Test
+ public void testGetNextTimeMonthlyReturnsFirstDayOfNextYear() {
+ final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM}.log.gz");
+ final Calendar initial = Calendar.getInstance();
+ initial.set(2015, Calendar.DECEMBER, 28, 0, 0, 0);
+ final long actual = pp.getNextTime(initial.getTimeInMillis(), 1, false);
+
+ // We expect 1st day of next month
+ final Calendar expected = Calendar.getInstance();
+ expected.set(2016, Calendar.JANUARY, 1, 00, 00, 00);
+ expected.set(Calendar.MILLISECOND, 0);
+ assertEquals(format(expected.getTimeInMillis()), format(actual));
+ }
+
+ @Test
public void testGetNextTimeMonthlyReturnsFirstDayOfNextMonth2() {
final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM}.log.gz");
final Calendar initial = Calendar.getInstance();
@@ -79,6 +94,27 @@ public class PatternProcessorTest {
}
@Test
+ @Ignore("https://issues.apache.org/jira/browse/LOG4J2-1232")
+ public void testGetNextTimeWeeklyReturnsFirstWeekInYear_US() {
+ final Locale old = Locale.getDefault();
+ Locale.setDefault(Locale.US); // force 1st day of the week to be Sunday
+ try {
+ final PatternProcessor pp = new PatternProcessor("logs/market_data_msg.log-%d{yyyy-MM-'W'W}");
+ final Calendar initial = Calendar.getInstance();
+ initial.set(2015, Calendar.DECEMBER, 28, 00, 00, 00); // Monday, December 28, 2015
+ final long actual = pp.getNextTime(initial.getTimeInMillis(), 1, false);
+
+ // expect Monday January 4, 2016
+ final Calendar expected = Calendar.getInstance();
+ expected.set(2016, Calendar.JANUARY, 4, 00, 00, 00);
+ expected.set(Calendar.MILLISECOND, 0);
+ assertEquals(format(expected.getTimeInMillis()), format(actual));
+ } finally {
+ Locale.setDefault(old);
+ }
+ }
+
+ @Test
public void testGetNextTimeWeeklyReturnsFirstDayOfNextWeek_US() {
final Locale old = Locale.getDefault();
Locale.setDefault(Locale.US); // force 1st day of the week to be Sunday
[50/50] logging-log4j2 git commit: Merge branch 'master' into
LOG4J-1181
Posted by mi...@apache.org.
Merge branch 'master' into LOG4J-1181
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/6e858b02
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/6e858b02
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/6e858b02
Branch: refs/heads/LOG4J-1181
Commit: 6e858b02f9f5513987788ab1120ca64c555cc989
Parents: e28d50b 0ae9948
Author: Mikael Ståldal <mi...@magine.com>
Authored: Tue Jan 12 17:47:51 2016 +0100
Committer: Mikael Ståldal <mi...@magine.com>
Committed: Tue Jan 12 17:47:51 2016 +0100
----------------------------------------------------------------------
RELEASE-NOTES.txt | 90 ++++---
log4j-1.2-api/pom.xml | 2 +-
.../java/org/apache/log4j/LogWithMDCTest.java | 19 +-
.../java/org/apache/log4j/LogWithRouteTest.java | 19 +-
log4j-api/pom.xml | 2 +-
.../java/org/apache/logging/log4j/Level.java | 18 +-
.../log4j/message/BasicThreadInformation.java | 2 +-
.../message/ExtendedThreadInformation.java | 3 +-
.../log4j/message/ThreadDumpMessage.java | 2 +-
.../apache/logging/log4j/spi/LoggerContext.java | 2 +
.../org/apache/logging/log4j/spi/Provider.java | 2 +-
.../logging/log4j/status/StatusLogger.java | 2 +-
.../apache/logging/log4j/util/LoaderUtil.java | 2 +-
.../logging/log4j/util/PropertiesUtil.java | 83 ++++--
log4j-bom/pom.xml | 2 +-
log4j-core/pom.xml | 2 +-
.../logging/log4j/core/LoggerContext.java | 51 ++--
.../appender/AbstractOutputStreamAppender.java | 27 +-
.../log4j/core/appender/AsyncAppender.java | 123 ++++++---
.../log4j/core/appender/ConsoleAppender.java | 63 ++++-
.../log4j/core/appender/FileManager.java | 6 +-
.../core/appender/MemoryMappedFileManager.java | 4 +-
.../core/appender/OutputStreamManager.java | 32 ++-
.../core/appender/RandomAccessFileManager.java | 6 +-
.../core/appender/RollingFileAppender.java | 1 -
.../log4j/core/appender/SmtpAppender.java | 7 +-
.../log4j/core/appender/SocketAppender.java | 144 +++++++---
.../appender/rolling/CronTriggeringPolicy.java | 16 +-
.../core/appender/rolling/PatternProcessor.java | 6 +
.../appender/rolling/RollingFileManager.java | 47 +++-
.../rolling/RollingRandomAccessFileManager.java | 6 +-
.../appender/rolling/action/DeleteAction.java | 78 +++++-
.../rolling/action/DeletingVisitor.java | 2 +-
.../rolling/action/ScriptCondition.java | 118 +++++++++
.../core/appender/routing/IdlePurgePolicy.java | 19 +-
.../core/appender/routing/PurgePolicy.java | 16 ++
.../log4j/core/async/AsyncEventRouter.java | 39 +++
.../core/async/AsyncEventRouterFactory.java | 117 ++++++++
.../logging/log4j/core/async/AsyncLogger.java | 45 ++--
.../log4j/core/async/AsyncLoggerConfig.java | 19 +-
.../core/async/AsyncLoggerConfigDelegate.java | 29 +-
.../core/async/AsyncLoggerConfigDisruptor.java | 82 +++---
.../log4j/core/async/AsyncLoggerDisruptor.java | 62 +++--
.../core/async/DefaultAsyncEventRouter.java | 38 +++
.../core/async/DiscardingAsyncEventRouter.java | 93 +++++++
.../logging/log4j/core/async/EventRoute.java | 99 +++++++
.../core/config/AbstractConfiguration.java | 57 ++--
.../log4j/core/config/AppendersPlugin.java | 5 +-
.../log4j/core/config/Configuration.java | 28 +-
.../core/config/ConfigurationScheduler.java | 1 +
.../builder/impl/DefaultComponentBuilder.java | 1 +
.../impl/DefaultConfigurationBuilder.java | 1 +
.../plugins/processor/PluginProcessor.java | 7 +-
.../core/config/plugins/util/ResolverUtil.java | 4 +-
.../logging/log4j/core/impl/Log4jLogEvent.java | 18 +-
.../log4j/core/layout/AbstractCsvLayout.java | 9 +-
.../core/layout/AbstractJacksonLayout.java | 26 +-
.../log4j/core/layout/AbstractLayout.java | 48 +++-
.../log4j/core/layout/AbstractStringLayout.java | 160 ++++++++---
.../log4j/core/layout/CsvLogEventLayout.java | 15 +-
.../log4j/core/layout/CsvParameterLayout.java | 15 +-
.../logging/log4j/core/layout/HtmlLayout.java | 2 +-
.../logging/log4j/core/layout/JsonLayout.java | 92 +++++--
.../log4j/core/layout/PatternLayout.java | 182 +++++++------
.../log4j/core/layout/SerializedLayout.java | 2 +-
.../logging/log4j/core/layout/XmlLayout.java | 2 +-
.../apache/logging/log4j/core/net/Protocol.java | 4 +-
.../logging/log4j/core/net/SmtpManager.java | 49 ++--
.../log4j/core/net/TcpSocketManager.java | 12 +-
.../net/ssl/AbstractKeyStoreConfiguration.java | 8 +-
.../log4j/core/net/ssl/SslConfiguration.java | 16 +-
.../log4j/core/pattern/PatternParser.java | 15 +-
.../log4j/core/script/ScriptManager.java | 78 +++---
.../logging/log4j/core/script/ScriptRef.java | 1 -
.../log4j/core/util/NanoClockFactory.java | 84 ------
.../log4j/core/util/StringBuilderWriter.java | 26 +-
log4j-core/src/main/resources/Log4j-config.xsd | 7 +-
.../logging/log4j/core/PatternSelectorTest.java | 6 +-
.../core/appender/ConsoleAppenderTest.java | 14 +-
.../log4j/core/appender/HangingAppender.java | 29 +-
.../appender/RandomAccessFileManagerTest.java | 2 +-
.../log4j/core/appender/SmtpAppenderTest.java | 17 +-
.../log4j/core/appender/SocketAppenderTest.java | 36 ++-
.../appender/rolling/PatternProcessorTest.java | 226 ++++++++++------
.../RollingAppenderDeleteScriptFri13thTest.java | 88 ++++++
.../RollingAppenderDeleteScriptTest.java | 85 ++++++
.../rolling/RollingAppenderSizeTest.java | 8 +-
.../RollingRandomAccessFileManagerTest.java | 9 +-
.../rolling/action/DeleteActionTest.java | 6 +-
.../rolling/action/ScriptConditionTest.java | 130 +++++++++
.../routing/RoutingAppenderWithPurgingTest.java | 13 +-
.../core/async/AsyncEventRouterFactoryTest.java | 153 +++++++++++
.../core/async/AsyncLoggerTestNanoTime.java | 15 +-
.../core/async/DefaultAsyncEventRouterTest.java | 67 +++++
.../async/DiscardingAsyncEventRouterTest.java | 146 ++++++++++
.../core/layout/CsvLogEventLayoutTest.java | 44 ++-
.../core/layout/CsvParameterLayoutTest.java | 4 +-
.../log4j/core/layout/JsonLayoutTest.java | 17 +-
.../layout/PatternLayoutMainMapLookupTest.java | 5 +-
.../log4j/core/layout/PatternLayoutTest.java | 4 +-
.../net/server/AbstractSocketServerTest.java | 15 +-
.../core/net/server/SslXmlSocketServerTest.java | 7 +-
.../net/server/TcpJsonSocketServerTest.java | 3 +-
.../server/TcpSerializedSocketServerTest.java | 3 +-
.../core/net/server/TcpXmlSocketServerTest.java | 3 +-
.../net/server/UdpJsonSocketServerTest.java | 3 +-
.../server/UdpSerializedSocketServerTest.java | 3 +-
.../core/net/server/UdpXmlSocketServerTest.java | 3 +-
.../log4j/core/pattern/PatternParserTest.java | 53 ++--
.../log4j/core/util/NanoClockFactoryTest.java | 65 -----
.../apache/logging/log4j/junit/CleanFiles.java | 2 +-
.../src/test/resources/JeroMqAppenderTest.xml | 2 +-
.../test/resources/LOG4J2-1100/log4j2-good.yaml | 2 +-
log4j-core/src/test/resources/LOG4J2-739.xml | 2 +-
log4j-core/src/test/resources/LOG4J2-807.xml | 2 +-
.../src/test/resources/log4j-customLevels.xml | 2 +-
.../resources/log4j-customLevelsOverride.xml | 2 +-
.../resources/log4j-customLevelsWithFilters.xml | 2 +-
.../src/test/resources/log4j-filetest.xml | 2 +-
.../src/test/resources/log4j-marker-lookup.yaml | 2 +-
...-rolling-with-custom-delete-accum-count1.xml | 2 +-
...-rolling-with-custom-delete-accum-count2.xml | 2 +-
...4j-rolling-with-custom-delete-accum-size.xml | 2 +-
...og4j-rolling-with-custom-delete-maxdepth.xml | 2 +-
.../log4j-rolling-with-custom-delete-nested.xml | 2 +-
...olling-with-custom-delete-script-fri13th.xml | 76 ++++++
.../log4j-rolling-with-custom-delete-script.xml | 76 ++++++
...olling-with-custom-delete-unconditional1.xml | 2 +-
...olling-with-custom-delete-unconditional2.xml | 2 +-
...olling-with-custom-delete-unconditional3.xml | 2 +-
.../log4j-rolling-with-custom-delete.xml | 2 +-
.../src/test/resources/log4j-routing-purge.xml | 10 +
log4j-core/src/test/resources/log4j2-962.xml | 2 +-
.../src/test/resources/perf9MMapNoLoc.xml | 2 +-
log4j-core/src/test/resources/rollover-test.xml | 2 +-
log4j-distribution/.gitignore | 2 +
log4j-distribution/pom.xml | 2 +-
log4j-flume-ng/pom.xml | 2 +-
.../log4j/flume/appender/FlumeAvroManager.java | 3 +-
.../src/test/resources/default_embedded.xml | 4 +-
log4j-flume-ng/src/test/resources/embedded.xml | 4 +-
log4j-iostreams/pom.xml | 2 +-
.../org/apache/logging/log4j/io/IoBuilder.java | 12 +-
log4j-jcl/pom.xml | 2 +-
log4j-jmx-gui/pom.xml | 2 +-
log4j-jul/pom.xml | 2 +-
log4j-liquibase/pom.xml | 2 +-
log4j-nosql/pom.xml | 2 +-
log4j-perf/pom.xml | 2 +-
log4j-samples/configuration/pom.xml | 2 +-
log4j-samples/flume-common/pom.xml | 2 +-
log4j-samples/flume-embedded/pom.xml | 4 +-
log4j-samples/flume-remote/pom.xml | 6 +-
log4j-samples/loggerProperties/pom.xml | 2 +-
log4j-samples/pom.xml | 2 +-
log4j-slf4j-impl/pom.xml | 2 +-
log4j-taglib/pom.xml | 2 +-
log4j-to-slf4j/pom.xml | 2 +-
.../slf4j/SLF4JLoggerContextFactory.java | 124 ++++-----
log4j-web/pom.xml | 2 +-
pom.xml | 28 +-
src/changes/announcement.vm | 14 +-
src/changes/changes.xml | 56 +++-
src/site/xdoc/faq.xml | 265 ++++++++++++-------
src/site/xdoc/manual/appenders.xml | 233 +++++++++++++---
src/site/xdoc/manual/async.xml | 128 +++++----
src/site/xdoc/manual/configuration.xml.vm | 41 ++-
src/site/xdoc/manual/filters.xml | 10 +-
168 files changed, 3676 insertions(+), 1402 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/6e858b02/pom.xml
----------------------------------------------------------------------
[23/50] logging-log4j2 git commit: Update maven-install-plugin from
2.4 to 2.5.2.
Posted by mi...@apache.org.
Update maven-install-plugin from 2.4 to 2.5.2.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/9fddd34c
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/9fddd34c
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/9fddd34c
Branch: refs/heads/LOG4J-1181
Commit: 9fddd34cda00e3b80aa4db805c2cbadeec4f0200
Parents: 88b394c
Author: ggregory <gg...@apache.org>
Authored: Wed Dec 30 23:21:54 2015 -0800
Committer: ggregory <gg...@apache.org>
Committed: Wed Dec 30 23:21:54 2015 -0800
----------------------------------------------------------------------
log4j-samples/flume-embedded/pom.xml | 2 +-
log4j-samples/flume-remote/pom.xml | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9fddd34c/log4j-samples/flume-embedded/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-samples/flume-embedded/pom.xml b/log4j-samples/flume-embedded/pom.xml
index 2095b96..a7847da 100644
--- a/log4j-samples/flume-embedded/pom.xml
+++ b/log4j-samples/flume-embedded/pom.xml
@@ -103,7 +103,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
- <version>2.4</version>
+ <version>2.5.2</version>
<configuration>
<skip>true</skip>
</configuration>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9fddd34c/log4j-samples/flume-remote/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-samples/flume-remote/pom.xml b/log4j-samples/flume-remote/pom.xml
index 015dbdf..868ac2a 100644
--- a/log4j-samples/flume-remote/pom.xml
+++ b/log4j-samples/flume-remote/pom.xml
@@ -91,7 +91,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
- <version>2.4</version>
+ <version>2.5.2</version>
<configuration>
<skip>true</skip>
</configuration>
[07/50] logging-log4j2 git commit: xml fix
Posted by mi...@apache.org.
xml fix
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/40344d63
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/40344d63
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/40344d63
Branch: refs/heads/LOG4J-1181
Commit: 40344d63815db80efb0a529e29f29ab70c828bd6
Parents: 5852711
Author: rpopma <rp...@apache.org>
Authored: Sun Dec 27 08:34:50 2015 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sun Dec 27 08:34:50 2015 +0900
----------------------------------------------------------------------
src/site/xdoc/manual/filters.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/40344d63/src/site/xdoc/manual/filters.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/manual/filters.xml b/src/site/xdoc/manual/filters.xml
index f44ec10..a53b3bf 100644
--- a/src/site/xdoc/manual/filters.xml
+++ b/src/site/xdoc/manual/filters.xml
@@ -584,7 +584,7 @@
</Root>
</Loggers>
</Configuration>
- ]]></pre>pre>
+ ]]></pre>
</subsection>
<a name="StructuredDataFilter"/>
<subsection name="StructuredDataFilter">
[03/50] logging-log4j2 git commit: LOG4J2-1080 change log entry
Posted by mi...@apache.org.
LOG4J2-1080 change log entry
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/8c310be2
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/8c310be2
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/8c310be2
Branch: refs/heads/LOG4J-1181
Commit: 8c310be2ec0f413f198fcbdb91648209f0f0f5f1
Parents: c484ec6
Author: rpopma <rp...@apache.org>
Authored: Wed Dec 23 22:15:56 2015 +0900
Committer: rpopma <rp...@apache.org>
Committed: Wed Dec 23 22:15:56 2015 +0900
----------------------------------------------------------------------
src/changes/changes.xml | 4 ++++
1 file changed, 4 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8c310be2/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 21893d4..8eb273e 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -24,6 +24,10 @@
</properties>
<body>
<release version="2.5.1" date="201Y-MM-DD" description="GA Release 2.5.1">
+ <action issue="LOG4J2-1080" dev="rpopma" type="add">
+ Added option to discard events below a certain log level if the async logger ring buffer
+ or async appender queue remaining capacity falls below a certain ratio.
+ </action>
<action issue="LOG4J2-1212" dev="rpopma" type="fix">
Fix documentation to correctly specify the blocking wait strategy as the default for async loggers.
</action>
[30/50] logging-log4j2 git commit: Fix typo in test assert message.
Posted by mi...@apache.org.
Fix typo in test assert message.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/27b3cb75
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/27b3cb75
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/27b3cb75
Branch: refs/heads/LOG4J-1181
Commit: 27b3cb759e18d2c9bc84a154749cf6ed0d56bb93
Parents: 7af6c05
Author: ggregory <gg...@apache.org>
Authored: Sat Jan 2 17:04:49 2016 -0800
Committer: ggregory <gg...@apache.org>
Committed: Sat Jan 2 17:04:49 2016 -0800
----------------------------------------------------------------------
.../src/test/java/org/apache/logging/log4j/junit/CleanFiles.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/27b3cb75/log4j-core/src/test/java/org/apache/logging/log4j/junit/CleanFiles.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/junit/CleanFiles.java b/log4j-core/src/test/java/org/apache/logging/log4j/junit/CleanFiles.java
index 7b962b7..69b0cdc 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/junit/CleanFiles.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/junit/CleanFiles.java
@@ -52,7 +52,7 @@ public class CleanFiles extends ExternalResource {
file.deleteOnExit();
}
assertTrue(
- "Could not delete " + file.toString() + ", last modifed "
+ "Could not delete " + file.toString() + ", last modified "
+ DateFormat.getInstance().format(new Date(file.lastModified())), deleted);
}
}
[41/50] logging-log4j2 git commit: Ignore Eclipse .settings folder.
Posted by mi...@apache.org.
Ignore Eclipse .settings folder.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/5656ffdd
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/5656ffdd
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/5656ffdd
Branch: refs/heads/LOG4J-1181
Commit: 5656ffdd406f801df3f891647e9bbe91e157a7d7
Parents: fb6fd31
Author: ggregory <gg...@apache.org>
Authored: Mon Jan 4 15:11:17 2016 -0800
Committer: ggregory <gg...@apache.org>
Committed: Mon Jan 4 15:11:17 2016 -0800
----------------------------------------------------------------------
log4j-distribution/.gitignore | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/5656ffdd/log4j-distribution/.gitignore
----------------------------------------------------------------------
diff --git a/log4j-distribution/.gitignore b/log4j-distribution/.gitignore
index d8fe4fa..58c32c8 100644
--- a/log4j-distribution/.gitignore
+++ b/log4j-distribution/.gitignore
@@ -1 +1,2 @@
/.project
+/.settings/
[49/50] logging-log4j2 git commit: [LOG4J2-1249] Update Jackson from
2.6.4 to 2.7.0.
Posted by mi...@apache.org.
[LOG4J2-1249] Update Jackson from 2.6.4 to 2.7.0.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/0ae9948d
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/0ae9948d
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/0ae9948d
Branch: refs/heads/LOG4J-1181
Commit: 0ae9948d75cb65538fb70aa0c4dbca48db45e5c7
Parents: 9d1ffa7
Author: ggregory <gg...@apache.org>
Authored: Mon Jan 11 18:53:07 2016 -0800
Committer: ggregory <gg...@apache.org>
Committed: Mon Jan 11 18:53:07 2016 -0800
----------------------------------------------------------------------
pom.xml | 2 +-
src/changes/changes.xml | 3 +++
2 files changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0ae9948d/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 890c2e3..b88ea5e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -190,7 +190,7 @@
<slf4jVersion>1.7.13</slf4jVersion>
<logbackVersion>1.1.3</logbackVersion>
<jackson1Version>1.9.13</jackson1Version>
- <jackson2Version>2.6.4</jackson2Version>
+ <jackson2Version>2.7.0</jackson2Version>
<springVersion>3.2.13.RELEASE</springVersion>
<flumeVersion>1.6.0</flumeVersion>
<disruptorVersion>3.3.2</disruptorVersion>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0ae9948d/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 63fb8c5..b4e9e79 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -67,6 +67,9 @@
<action issue="LOG4J2-1239" dev="ggregory" type="update">
Update Jackson from 2.6.3 to 2.6.4.
</action>
+ <action issue="LOG4J2-1249" dev="ggregory" type="update">
+ Update Jackson from 2.6.4 to 2.7.0.
+ </action>
<action issue="LOG4J2-1240" dev="ggregory" type="update">
Update Liquibase from 3.3.5 to 3.4.2.
</action>
[18/50] logging-log4j2 git commit: [LOG4J2-1238]
org.apache.logging.log4j.core.net.TcpSocketManager and other classes does not
report internal exceptions to the status logger. Better description of the
issue.
Posted by mi...@apache.org.
[LOG4J2-1238] org.apache.logging.log4j.core.net.TcpSocketManager and
other classes does not report internal exceptions to the status logger.
Better description of the issue.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/673756bd
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/673756bd
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/673756bd
Branch: refs/heads/LOG4J-1181
Commit: 673756bdf9d05b0b9af1c8a0680b2cbf7b6c6844
Parents: 2409000
Author: ggregory <gg...@apache.org>
Authored: Wed Dec 30 20:11:16 2015 -0800
Committer: ggregory <gg...@apache.org>
Committed: Wed Dec 30 20:11:16 2015 -0800
----------------------------------------------------------------------
src/changes/changes.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/673756bd/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index dee5215..a6fdd65 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -32,7 +32,7 @@
JSONLayout doesn't add a comma between log events.
</action>
<action issue="LOG4J2-1238" dev="ggregory" type="fix">
- org.apache.logging.log4j.core.net.TcpSocketManager does not display stack traces.
+ org.apache.logging.log4j.core.net.TcpSocketManager and other classes does not report internal exceptions to the status logger.
</action>
<action issue="LOG4J2-1212" dev="rpopma" type="fix">
Fix documentation to correctly specify the blocking wait strategy as the default for async loggers.
[08/50] logging-log4j2 git commit: LOG4J2-435 improved documentation
Posted by mi...@apache.org.
LOG4J2-435 improved documentation
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/d5f73500
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/d5f73500
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/d5f73500
Branch: refs/heads/LOG4J-1181
Commit: d5f7350090e0f6c786314592f291ac79e3c51ee4
Parents: 40344d6
Author: rpopma <rp...@apache.org>
Authored: Sun Dec 27 09:07:14 2015 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sun Dec 27 09:07:14 2015 +0900
----------------------------------------------------------------------
src/site/xdoc/faq.xml | 36 +++++++++++++++++++++++----------
src/site/xdoc/manual/appenders.xml | 4 +++-
2 files changed, 28 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d5f73500/src/site/xdoc/faq.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/faq.xml b/src/site/xdoc/faq.xml
index 7c4aa87..8dc198f 100644
--- a/src/site/xdoc/faq.xml
+++ b/src/site/xdoc/faq.xml
@@ -35,10 +35,11 @@
<li><a href="#config_sep_appender_level">How do I send log messages with different levels to different appenders?</a></li>
<li><a href="#troubleshooting">How do I debug my configuration?</a></li>
<li><a href="#separate_log_files">How do I dynamically write to separate log files?</a></li>
- <li><a href="#reconfig_level_from_code">How do I set a logger's level programmatically?</a></li>
- <!--
- <li><a href="#custom_plugin">How do I get log4j2 to recognize my custom plugin?</a></li>
- -->
+ <li><a href="#reconfig_level_from_code">How do I set a logger's level programmatically?</a></li>
+ <li><a href="#retention">How do I set my log archive retention policy? How do I delete old log archives?</a></li>
+ <!--
+ <li><a href="#custom_plugin">How do I get log4j2 to recognize my custom plugin?</a></li>
+ -->
</ul>
<subsection>
<a name="missing_core" />
@@ -60,7 +61,7 @@
The component page will have more detail.
For example, the <a href="log4j-core/index.html">log4j-core component page</a>
has an outline of which log4j-core features have external dependencies.</p>
-
+
<a name="config_location" />
<h4>How do I specify the configuration file location?</h4>
<p>By default, Log4j looks for a configuration file named <b>log4j2.xml</b> (not log4j.xml) in the classpath.
@@ -74,9 +75,9 @@
<a name="config_from_code" />
<h4>How do I configure log4j2 in code without a configuration file?</h4>
<p>Starting with version 2.4, Log4j 2 provides an <a href="manual/customconfig.html">API
- for programmatic configuration</a>.
+ for programmatic configuration</a>.
The new <a href="log4j-core/apidocs/org/apache/logging/log4j/core/config/builder/api/ConfigurationBuilder.html">ConfigurationBuilder
- API</a> allows you to create Configurations in code by constructing component definitions
+ API</a> allows you to create Configurations in code by constructing component definitions
without requiring you to know about the internals of actual configuration objects like Loggers and Appenders.</p>
<a name="reconfig_from_code" />
@@ -97,7 +98,7 @@ context.setConfigLocation(file.toURI());
<p>Normally there is no need to do this manually.
Each LoggerContext registers a shutdown hook that takes care of releasing resources
when the JVM exits (unless system property <code>log4j.shutdownHookEnabled</code>
- is set to <code>false</code>).
+ is set to <code>false</code>).
Web applications should include the log4j-web
module in their classpath which disables the shutdown hook but instead
cleans up log4j resources when the web application is stopped.</p>
@@ -137,7 +138,7 @@ Configurator.shutdown(context);</pre>
<a name="troubleshooting" />
<h4>How do I debug my configuration?</h4>
- <p>First, make sure you have <a href="#which_jars">the right jar files</a> on your classpath.
+ <p>First, make sure you have <a href="#which_jars">the right jar files</a> on your classpath.
You need at least log4j-api and log4j-core.</p>
<p>Next, check the name of your configuration file. By default, log4j2 will look
for a configuration file named <code>log4j2.xml</code> on the classpath. Note the "2" in the file name!
@@ -150,8 +151,8 @@ Configurator.shutdown(context);</pre>
This may be useful to trouble-shoot configuration issues.
By default the status logger level is WARN, so you only see notifications when there is a problem.
</p>
- <p>If the configuration file is not found correctly, you can still enable
- log4j2 internal status logging by setting system property
+ <p>If the configuration file is not found correctly, you can still enable
+ log4j2 internal status logging by setting system property
<code>-Dorg.apache.logging.log4j.simplelog.StatusLogger.level=TRACE</code>.</p>
<a name="separate_log_files" />
@@ -226,6 +227,19 @@ Configurator.setLevel("com.example.Foo", Level.DEBUG);
Configurator.setRootLevel(Level.DEBUG);
</pre>
+ <a name="retention" />
+ <h4>How do I set my log archive retention policy? How do I delete old log archives?</h4>
+ <p>The <tt>DefaultRolloverStrategy</tt> of the Rolling File appender (and Rolling Random Access File
+ appender) supports a <a href="manual/appenders.html#CustomDeleteOnRollover">Delete</a>
+ element.</p>
+ <p>Starting at a specified base directory, you can delete all files for which some condition
+ holds true, for example all files that match a given file name pattern and are older
+ than some number of days. More complex conditions are possible, and if the built-in
+ conditions are not sufficient, users can provide
+ custom conditions by creating
+ <a href="manual/appenders.html#DeletePathCondition">plugin conditions</a> or by
+ writing a <a href="manual/appenders.html#ScriptCondition">script condition</a>
+ </p>
<!--
<a name="custom_plugin" />
<h4>How do I get log4j2 to recognize my custom plugin?</h4>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d5f73500/src/site/xdoc/manual/appenders.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/manual/appenders.xml b/src/site/xdoc/manual/appenders.xml
index 69ed1a0..817fb1f 100644
--- a/src/site/xdoc/manual/appenders.xml
+++ b/src/site/xdoc/manual/appenders.xml
@@ -2485,7 +2485,7 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
</Loggers>
</Configuration>]]></pre>
<a name="CustomDeleteOnRollover"/>
- <h5>Custom Delete on Rollover</h5>
+ <h5>Log Archive Retention Policy: Delete on Rollover</h5>
<p>
Log4j-2.5 introduces a <tt>Delete</tt> action that gives users more control
over what files are deleted at rollover time than what was possible with the DefaultRolloverStrategy
@@ -2751,6 +2751,8 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
</Policies>
<DefaultRolloverStrategy max="100">
<!--
+ Nested conditions: the inner condition is only evaluated for files
+ where the outer conditions are true.
-->
<Delete basePath="${baseDir}" maxDepth="2">
<IfFileName glob="*/app-*.log.gz">
[34/50] logging-log4j2 git commit: [LOG4J2-1237] Make PatternLayout
header and footer accept a pattern.
Posted by mi...@apache.org.
[LOG4J2-1237] Make PatternLayout header and footer accept a pattern.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/c3d8ce82
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/c3d8ce82
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/c3d8ce82
Branch: refs/heads/LOG4J-1181
Commit: c3d8ce8240202ff92da0c239092b13aa347bae36
Parents: 6944134
Author: ggregory <gg...@apache.org>
Authored: Sun Jan 3 22:14:20 2016 -0800
Committer: ggregory <gg...@apache.org>
Committed: Sun Jan 3 22:14:20 2016 -0800
----------------------------------------------------------------------
.../log4j/core/layout/AbstractStringLayout.java | 30 ++--
.../log4j/core/layout/PatternLayout.java | 163 +++++++++++--------
.../log4j/core/layout/PatternLayoutTest.java | 4 +-
src/changes/changes.xml | 3 +
4 files changed, 112 insertions(+), 88 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c3d8ce82/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java
index 68b9fb6..96a80a5 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java
@@ -75,6 +75,21 @@ public abstract class AbstractStringLayout extends AbstractLayout<String> implem
&& (StandardCharsets.ISO_8859_1.equals(charset) || StandardCharsets.US_ASCII.equals(charset));
}
+ /**
+ * Returns a {@code StringBuilder} that this Layout implementation can use to write the formatted log event to.
+ *
+ * @return a {@code StringBuilder}
+ */
+ protected static StringBuilder getStringBuilder() {
+ StringBuilder result = threadLocal.get();
+ if (result == null) {
+ result = new StringBuilder(DEFAULT_STRING_BUILDER_SIZE);
+ threadLocal.set(result);
+ }
+ result.setLength(0);
+ return result;
+ }
+
// LOG4J2-1151: If the built-in JDK 8 encoders are available we should use them.
private static boolean isPreJava8() {
final String version = System.getProperty("java.version");
@@ -98,21 +113,6 @@ public abstract class AbstractStringLayout extends AbstractLayout<String> implem
charset = Charset.forName(csName);
}
- /**
- * Returns a {@code StringBuilder} that this Layout implementation can use to write the formatted log event to.
- *
- * @return a {@code StringBuilder}
- */
- protected StringBuilder getStringBuilder() {
- StringBuilder result = threadLocal.get();
- if (result == null) {
- result = new StringBuilder(DEFAULT_STRING_BUILDER_SIZE);
- threadLocal.set(result);
- }
- result.setLength(0);
- return result;
- }
-
protected byte[] getBytes(final String s) {
if (useCustomEncoding) { // rely on branch prediction to eliminate this check if false
return StringEncoder.encodeSingleByteChars(s);
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c3d8ce82/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java
index cda7915..63c44fd 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java
@@ -25,6 +25,7 @@ import org.apache.logging.log4j.core.Layout;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.DefaultConfiguration;
+import org.apache.logging.log4j.core.config.LoggerConfig;
import org.apache.logging.log4j.core.config.Node;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
@@ -38,6 +39,7 @@ import org.apache.logging.log4j.core.pattern.PatternFormatter;
import org.apache.logging.log4j.core.pattern.PatternParser;
import org.apache.logging.log4j.core.pattern.RegexReplacement;
import org.apache.logging.log4j.core.util.StringEncoder;
+import org.apache.logging.log4j.util.Strings;
/**
* A flexible layout configurable with pattern string.
@@ -57,25 +59,20 @@ import org.apache.logging.log4j.core.util.StringEncoder;
public final class PatternLayout extends AbstractStringLayout {
/**
- * Default pattern string for log output. Currently set to the
- * string <b>"%m%n"</b> which just prints the application supplied
- * message.
+ * Default pattern string for log output. Currently set to the string <b>"%m%n"</b> which just prints the
+ * application supplied message.
*/
public static final String DEFAULT_CONVERSION_PATTERN = "%m%n";
/**
- * A conversion pattern equivalent to the TTCCCLayout.
- * Current value is <b>%r [%t] %p %c %x - %m%n</b>.
+ * A conversion pattern equivalent to the TTCCCLayout. Current value is <b>%r [%t] %p %c %x - %m%n</b>.
*/
- public static final String TTCC_CONVERSION_PATTERN =
- "%r [%t] %p %c %x - %m%n";
+ public static final String TTCC_CONVERSION_PATTERN = "%r [%t] %p %c %x - %m%n";
/**
- * A simple pattern.
- * Current value is <b>%d [%t] %p %c - %m%n</b>.
+ * A simple pattern. Current value is <b>%d [%t] %p %c - %m%n</b>.
*/
- public static final String SIMPLE_CONVERSION_PATTERN =
- "%d [%t] %p %c - %m%n";
+ public static final String SIMPLE_CONVERSION_PATTERN = "%d [%t] %p %c - %m%n";
/** Key to identify pattern converters. */
public static final String KEY = "Converter";
@@ -83,87 +80,92 @@ public final class PatternLayout extends AbstractStringLayout {
private static final long serialVersionUID = 1L;
/**
- * Initial converter for pattern.
- */
- private final PatternFormatter[] formatters;
-
- /**
* Conversion pattern.
*/
private final String conversionPattern;
private final PatternSelector patternSelector;
- private final Serializer serializer;
+ private final Serializer eventSerializer;
+
+ private final Serializer headerSerializer;
+ private final Serializer footerSerializer;
/**
* The current Configuration.
*/
private final Configuration config;
- private final RegexReplacement replace;
-
- private final boolean alwaysWriteExceptions;
-
- private final boolean noConsoleNoAnsi;
-
/**
* Constructs a EnhancedPatternLayout using the supplied conversion pattern.
*
* @param config The Configuration.
* @param replace The regular expression to match.
- * @param pattern conversion pattern.
+ * @param eventPattern conversion pattern.
* @param patternSelector The PatternSelector.
* @param charset The character set.
* @param alwaysWriteExceptions Whether or not exceptions should always be handled in this pattern (if {@code true},
* exceptions will be written even if the pattern does not specify so).
* @param noConsoleNoAnsi
* If {@code "true"} (default) and {@link System#console()} is null, do not output ANSI escape codes
- * @param header
+ * @param headerPattern header conversion pattern.
+ * @param footerPattern footer conversion pattern.
*/
- private PatternLayout(final Configuration config, final RegexReplacement replace, final String pattern,
- final PatternSelector patternSelector, final Charset charset,
- final boolean alwaysWriteExceptions, final boolean noConsoleNoAnsi,
- final String header, final String footer) {
- super(charset, StringEncoder.toBytes(header, charset), StringEncoder.toBytes(footer, charset));
- this.replace = replace;
- this.conversionPattern = pattern;
+ private PatternLayout(final Configuration config, final RegexReplacement replace, final String eventPattern,
+ final PatternSelector patternSelector, final Charset charset, final boolean alwaysWriteExceptions,
+ final boolean noConsoleNoAnsi, final String headerPattern, final String footerPattern) {
+ super(charset, StringEncoder.toBytes(headerPattern, charset), StringEncoder.toBytes(footerPattern, charset));
+ this.conversionPattern = eventPattern;
this.patternSelector = patternSelector;
this.config = config;
- this.alwaysWriteExceptions = alwaysWriteExceptions;
- this.noConsoleNoAnsi = noConsoleNoAnsi;
+ this.eventSerializer = createSerializer(config, replace, eventPattern, DEFAULT_CONVERSION_PATTERN, patternSelector,
+ alwaysWriteExceptions, noConsoleNoAnsi);
+ this.headerSerializer = createSerializer(config, replace, headerPattern, null, patternSelector,
+ alwaysWriteExceptions, noConsoleNoAnsi);
+ this.footerSerializer = createSerializer(config, replace, footerPattern, null, patternSelector,
+ alwaysWriteExceptions, noConsoleNoAnsi);
+ }
+
+ private Serializer createSerializer(final Configuration configuration, final RegexReplacement replace,
+ final String pattern, final String defaultPattern, final PatternSelector patternSelector,
+ final boolean alwaysWriteExceptions, final boolean noConsoleNoAnsi) {
+ if (Strings.isEmpty(pattern) && Strings.isEmpty(defaultPattern)) {
+ return null;
+ }
if (patternSelector == null) {
- serializer = new PatternSerializer();
- final PatternParser parser = createPatternParser(config);
+ final PatternParser parser = createPatternParser(configuration);
try {
- List<PatternFormatter> list = parser.parse(pattern == null ? DEFAULT_CONVERSION_PATTERN : pattern,
- this.alwaysWriteExceptions, this.noConsoleNoAnsi);
- this.formatters = list.toArray(new PatternFormatter[0]);
- } catch (RuntimeException ex) {
+ final List<PatternFormatter> list = parser.parse(pattern == null ? defaultPattern : pattern,
+ alwaysWriteExceptions, noConsoleNoAnsi);
+ final PatternFormatter[] formatters = list.toArray(new PatternFormatter[0]);
+ return new PatternSerializer(formatters, replace);
+ } catch (final RuntimeException ex) {
throw new IllegalArgumentException("Cannot parse pattern '" + pattern + "'", ex);
}
- } else {
- this.formatters = null;
- serializer = new PatternSelectorSerializer();
}
- }
-
- private byte[] strSubstitutorReplace(final byte... b) {
- if (b != null && config != null) {
- return getBytes(config.getStrSubstitutor().replace(new String(b, getCharset())));
- }
- return b;
+ return new PatternSelectorSerializer(patternSelector, replace);
}
@Override
public byte[] getHeader() {
- return strSubstitutorReplace(super.getHeader());
+ return serializeHeaderFooter(headerSerializer);
}
@Override
public byte[] getFooter() {
- return strSubstitutorReplace(super.getFooter());
+ return serializeHeaderFooter(footerSerializer);
+ }
+
+ private byte[] serializeHeaderFooter(final Serializer serializer) {
+ if (serializer == null) {
+ return null;
+ }
+ final LoggerConfig rootLogger = config.getRootLogger();
+ // Using "" for the FQCN, does it matter?
+ final LogEvent logEvent = rootLogger.getLogEventFactory().createEvent(rootLogger.getName(), null, Strings.EMPTY,
+ rootLogger.getLevel(), null, null, null);
+ return StringEncoder.toBytes(serializer.toSerializable(logEvent), getCharset());
}
/**
@@ -186,8 +188,7 @@ public final class PatternLayout extends AbstractStringLayout {
* @return Map of content format keys supporting PatternLayout
*/
@Override
- public Map<String, String> getContentFormat()
- {
+ public Map<String, String> getContentFormat() {
final Map<String, String> result = new HashMap<>();
result.put("structured", "false");
result.put("formatType", "conversion");
@@ -203,7 +204,7 @@ public final class PatternLayout extends AbstractStringLayout {
*/
@Override
public String toSerializable(final LogEvent event) {
- return serializer.toSerializable(event);
+ return eventSerializer.toSerializable(event);
}
/**
@@ -246,9 +247,9 @@ public final class PatternLayout extends AbstractStringLayout {
* If {@code "true"} (default) exceptions are always written even if the pattern contains no exception tokens.
* @param noConsoleNoAnsi
* If {@code "true"} (default is false) and {@link System#console()} is null, do not output ANSI escape codes
- * @param header
+ * @param headerPattern
* The footer to place at the top of the document, once.
- * @param footer
+ * @param footerPattern
* The footer to place at the bottom of the document, once.
* @return The PatternLayout.
*/
@@ -262,8 +263,8 @@ public final class PatternLayout extends AbstractStringLayout {
@PluginAttribute(value = "charset") final Charset charset,
@PluginAttribute(value = "alwaysWriteExceptions", defaultBoolean = true) final boolean alwaysWriteExceptions,
@PluginAttribute(value = "noConsoleNoAnsi", defaultBoolean = false) final boolean noConsoleNoAnsi,
- @PluginAttribute("header") final String header,
- @PluginAttribute("footer") final String footer) {
+ @PluginAttribute("header") final String headerPattern,
+ @PluginAttribute("footer") final String footerPattern) {
return newBuilder()
.withPattern(pattern)
.withPatternSelector(patternSelector)
@@ -272,18 +273,27 @@ public final class PatternLayout extends AbstractStringLayout {
.withCharset(charset)
.withAlwaysWriteExceptions(alwaysWriteExceptions)
.withNoConsoleNoAnsi(noConsoleNoAnsi)
- .withHeader(header)
- .withFooter(footer)
+ .withHeader(headerPattern)
+ .withFooter(footerPattern)
.build();
}
-
private interface Serializer {
-
- String toSerializable(final LogEvent event);
+
+ String toSerializable(final LogEvent event);
}
- private class PatternSerializer implements Serializer {
+ private static class PatternSerializer implements Serializer {
+
+ private final PatternFormatter[] formatters;
+ private final RegexReplacement replace;
+
+ private PatternSerializer(final PatternFormatter[] formatters, final RegexReplacement replace) {
+ super();
+ this.formatters = formatters;
+ this.replace = replace;
+ }
+
@Override
public String toSerializable(final LogEvent event) {
final StringBuilder buf = getStringBuilder();
@@ -299,11 +309,21 @@ public final class PatternLayout extends AbstractStringLayout {
}
}
- private class PatternSelectorSerializer implements Serializer {
+ private static class PatternSelectorSerializer implements Serializer {
+
+ private final PatternSelector patternSelector;
+ private final RegexReplacement replace;
+
+ private PatternSelectorSerializer(final PatternSelector patternSelector, final RegexReplacement replace) {
+ super();
+ this.patternSelector = patternSelector;
+ this.replace = replace;
+ }
+
@Override
public String toSerializable(final LogEvent event) {
final StringBuilder buf = getStringBuilder();
- PatternFormatter[] formatters = patternSelector.getFormatters(event);
+ final PatternFormatter[] formatters = patternSelector.getFormatters(event);
final int len = formatters.length;
for (int i = 0; i < len; i++) {
formatters[i].format(event, buf);
@@ -328,21 +348,21 @@ public final class PatternLayout extends AbstractStringLayout {
}
/**
- * Creates a PatternLayout using the default options and the given
- * configuration. These options include using UTF-8, the default conversion
- * pattern, exceptions being written, and with ANSI escape codes.
+ * Creates a PatternLayout using the default options and the given configuration. These options include using UTF-8,
+ * the default conversion pattern, exceptions being written, and with ANSI escape codes.
*
* @param configuration The Configuration.
*
* @return the PatternLayout.
* @see #DEFAULT_CONVERSION_PATTERN Default conversion pattern
*/
- public static PatternLayout createDefaultLayout(Configuration configuration) {
+ public static PatternLayout createDefaultLayout(final Configuration configuration) {
return newBuilder().withConfiguration(configuration).build();
}
/**
* Creates a builder for a custom PatternLayout.
+ *
* @return a PatternLayout builder.
*/
@PluginBuilderFactory
@@ -398,7 +418,6 @@ public final class PatternLayout extends AbstractStringLayout {
return this;
}
-
public Builder withConfiguration(final Configuration configuration) {
this.configuration = configuration;
return this;
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c3d8ce82/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java
index 53335d6..b10c8f5 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java
@@ -82,6 +82,7 @@ public class PatternLayoutTest {
assertTrue(headerStr, headerStr.contains("(build "));
assertTrue(headerStr, headerStr.contains(" from "));
assertTrue(headerStr, headerStr.contains(" architecture: "));
+ assertFalse(headerStr, headerStr.contains("%d{UNIX}"));
//
final byte[] footer = layout.getFooter();
assertNotNull("No footer", footer);
@@ -91,6 +92,7 @@ public class PatternLayoutTest {
assertTrue(footerStr, footerStr.contains("(build "));
assertTrue(footerStr, footerStr.contains(" from "));
assertTrue(footerStr, footerStr.contains(" architecture: "));
+ assertFalse(footerStr, footerStr.contains("%d{UNIX}"));
}
/**
@@ -323,7 +325,7 @@ public class PatternLayoutTest {
.setIncludeLocation(true)
.setMessage(new SimpleMessage("entry")).build();
final String result1 = new FauxLogger().formatEvent(event1, layout);
- final String expectSuffix1 = String.format("====== PatternLayoutTest.testPatternSelector:325 entry ======%n");
+ final String expectSuffix1 = String.format("====== PatternLayoutTest.testPatternSelector:327 entry ======%n");
assertTrue("Unexpected result: " + result1, result1.endsWith(expectSuffix1));
final LogEvent event2 = Log4jLogEvent.newBuilder() //
.setLoggerName(this.getClass().getName()).setLoggerFqcn("org.apache.logging.log4j.core.Logger") //
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c3d8ce82/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index a4b6798..6c36be1 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -28,6 +28,9 @@
Added option to discard events below a certain log level if the async logger ring buffer
or async appender queue remaining capacity falls below a certain ratio.
</action>
+ <action issue="LOG4J2-1237" dev="ggregory" type="add" due-to="Mike Calmus, Gary Gregory">
+ Make PatternLayout header and footer accept a pattern.
+ </action>
<action issue="LOG4J2-908" dev="ggregory" type="fix" due-to="Konstantinos Liakos, Patrick Flaherty, Robin Coe, Gary Gregory">
JSONLayout doesn't add a comma between log events.
</action>
[21/50] logging-log4j2 git commit: Update clirr-maven-plugin from
2.6.1 to 2.7.
Posted by mi...@apache.org.
Update clirr-maven-plugin from 2.6.1 to 2.7.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/7c659ce4
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/7c659ce4
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/7c659ce4
Branch: refs/heads/LOG4J-1181
Commit: 7c659ce48936ab07579b7f4aed48100b21127c14
Parents: 680126b
Author: ggregory <gg...@apache.org>
Authored: Wed Dec 30 23:07:58 2015 -0800
Committer: ggregory <gg...@apache.org>
Committed: Wed Dec 30 23:07:58 2015 -0800
----------------------------------------------------------------------
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7c659ce4/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index f6c89c8..ce0e831 100644
--- a/pom.xml
+++ b/pom.xml
@@ -210,7 +210,7 @@
<release.plugin.version>2.5.3</release.plugin.version>
<scm.plugin.version>1.9.4</scm.plugin.version>
<jxr.plugin.version>2.5</jxr.plugin.version>
- <clirr.plugin.version>2.6.1</clirr.plugin.version>
+ <clirr.plugin.version>2.7</clirr.plugin.version>
<site.plugin.version>3.4</site.plugin.version>
<manifestfile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestfile>
<maven.compile.source>1.7</maven.compile.source>
[16/50] logging-log4j2 git commit: Log exception to status logger.
Posted by mi...@apache.org.
Log exception to status logger.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/8b9962c6
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/8b9962c6
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/8b9962c6
Branch: refs/heads/LOG4J-1181
Commit: 8b9962c646e18663cb5344e7e1206996225b2c4e
Parents: f965d51
Author: ggregory <gg...@apache.org>
Authored: Wed Dec 30 17:11:13 2015 -0800
Committer: ggregory <gg...@apache.org>
Committed: Wed Dec 30 17:11:13 2015 -0800
----------------------------------------------------------------------
.../log4j/core/net/ssl/AbstractKeyStoreConfiguration.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8b9962c6/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/AbstractKeyStoreConfiguration.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/AbstractKeyStoreConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/AbstractKeyStoreConfiguration.java
index 6034038..57fd791 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/AbstractKeyStoreConfiguration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/AbstractKeyStoreConfiguration.java
@@ -52,19 +52,19 @@ public class AbstractKeyStoreConfiguration extends StoreConfiguration<KeyStore>
return ks;
}
} catch (final CertificateException e) {
- LOGGER.error("No Provider supports a KeyStoreSpi implementation for the specified type {}", this.keyStoreType);
+ LOGGER.error("No Provider supports a KeyStoreSpi implementation for the specified type" + this.keyStoreType, e);
throw new StoreConfigurationException(e);
} catch (final NoSuchAlgorithmException e) {
- LOGGER.error("The algorithm used to check the integrity of the keystore cannot be found");
+ LOGGER.error("The algorithm used to check the integrity of the keystore cannot be found", e);
throw new StoreConfigurationException(e);
} catch (final KeyStoreException e) {
LOGGER.error(e);
throw new StoreConfigurationException(e);
} catch (final FileNotFoundException e) {
- LOGGER.error("The keystore file({}) is not found", this.getLocation());
+ LOGGER.error("The keystore file(" + this.getLocation() + ") is not found", e);
throw new StoreConfigurationException(e);
} catch (final IOException e) {
- LOGGER.error("Something is wrong with the format of the keystore or the given password");
+ LOGGER.error("Something is wrong with the format of the keystore or the given password", e);
throw new StoreConfigurationException(e);
}
}
[46/50] logging-log4j2 git commit: formatting
Posted by mi...@apache.org.
formatting
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/102bcec0
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/102bcec0
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/102bcec0
Branch: refs/heads/LOG4J-1181
Commit: 102bcec062ec57ca67f0473e696863e60653810d
Parents: d6b7f48
Author: rpopma <rp...@apache.org>
Authored: Sat Jan 9 15:58:30 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sat Jan 9 15:58:30 2016 +0900
----------------------------------------------------------------------
.../logging/log4j/core/impl/Log4jLogEvent.java | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/102bcec0/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 25a32af..4fe1b38 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
@@ -85,10 +85,10 @@ public class Log4jLogEvent implements LogEvent {
private boolean includeLocation;
private boolean endOfBatch = false;
private long nanoTime;
-
+
public Builder() {
}
-
+
public Builder(LogEvent other) {
Objects.requireNonNull(other);
if (other instanceof RingBufferLogEvent) {
@@ -108,7 +108,7 @@ public class Log4jLogEvent implements LogEvent {
this.includeLocation = other.isIncludeLocation();
this.endOfBatch = other.isEndOfBatch();
this.nanoTime = other.getNanoTime();
-
+
// Avoid unnecessarily initializing thrownProxy, threadName and source if possible
if (other instanceof Log4jLogEvent) {
Log4jLogEvent evt = (Log4jLogEvent) other;
@@ -325,7 +325,7 @@ public Log4jLogEvent(final String loggerName, final Marker marker, final String
final Map<String, String> mdc, final ThreadContext.ContextStack ndc,
final String threadName, final StackTraceElement location,
final long timestamp) {
- final Log4jLogEvent result = new Log4jLogEvent(loggerName, marker, loggerFQCN, level, message, thrown,
+ final Log4jLogEvent result = new Log4jLogEvent(loggerName, marker, loggerFQCN, level, message, thrown,
thrownProxy, mdc, ndc, threadName, location, timestamp, nanoClock.nanoTime());
return result;
}
@@ -343,7 +343,7 @@ public Log4jLogEvent(final String loggerName, final Marker marker, final String
* @param contextStack the nested diagnostic context.
* @param threadName The name of the thread.
* @param source The locations of the caller.
- * @param timestamp The timestamp of the event.
+ * @param timestampMillis The timestamp of the event.
* @param nanoTime The value of the running Java Virtual Machine's high-resolution time source when the event was
* created.
*/
@@ -385,7 +385,7 @@ public Log4jLogEvent(final String loggerName, final Marker marker, final String
}
return Collections.unmodifiableMap(map);
}
-
+
/**
* Returns the {@code NanoClock} to use for creating the nanoTime timestamp of log events.
* @return the {@code NanoClock} to use for creating the nanoTime timestamp of log events
@@ -393,20 +393,20 @@ public Log4jLogEvent(final String loggerName, final Marker marker, final String
public static NanoClock getNanoClock() {
return nanoClock;
}
-
+
/**
* Sets the {@code NanoClock} to use for creating the nanoTime timestamp of log events.
* <p>
* FOR INTERNAL USE. This method may be called with a different {@code NanoClock} implementation when the
* configuration changes.
- *
+ *
* @param nanoClock the {@code NanoClock} to use for creating the nanoTime timestamp of log events
*/
public static void setNanoClock(NanoClock nanoClock) {
Log4jLogEvent.nanoClock = Objects.requireNonNull(nanoClock, "NanoClock must be non-null");
StatusLogger.getLogger().trace("Using {} for nanosecond timestamps.", nanoClock.getClass().getSimpleName());
}
-
+
/**
* Returns a new fully initialized {@code Log4jLogEvent.Builder} containing a copy of all fields of this event.
* @return a new fully initialized builder.
[06/50] logging-log4j2 git commit: Merge remote-tracking branch
'origin/master'
Posted by mi...@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/5852711b
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/5852711b
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/5852711b
Branch: refs/heads/LOG4J-1181
Commit: 5852711b8e19bf218c0c192953db6c50b09c5601
Parents: 1286d96 7c5bb52
Author: rpopma <rp...@apache.org>
Authored: Sun Dec 27 08:32:52 2015 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sun Dec 27 08:32:52 2015 +0900
----------------------------------------------------------------------
log4j-distribution/.gitignore | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
[12/50] logging-log4j2 git commit: Pick up Javadoc updates from
revision 1722253.
Posted by mi...@apache.org.
Pick up Javadoc updates from revision 1722253.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/70ddbaf8
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/70ddbaf8
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/70ddbaf8
Branch: refs/heads/LOG4J-1181
Commit: 70ddbaf8a2f798cb440c8333698f3555212b11c3
Parents: 2d98964
Author: ggregory <gg...@apache.org>
Authored: Tue Dec 29 16:38:54 2015 -0800
Committer: ggregory <gg...@apache.org>
Committed: Tue Dec 29 16:38:54 2015 -0800
----------------------------------------------------------------------
.../log4j/core/util/StringBuilderWriter.java | 26 +++++++++++---------
1 file changed, 15 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/70ddbaf8/log4j-core/src/main/java/org/apache/logging/log4j/core/util/StringBuilderWriter.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/StringBuilderWriter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/StringBuilderWriter.java
index 15bc4ab..d366bd6 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/StringBuilderWriter.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/StringBuilderWriter.java
@@ -27,8 +27,12 @@ import java.io.Writer;
* (i.e. for use in a single thread) implementation for better performance.
* For safe usage with multiple {@link Thread}s then
* <code>java.io.StringWriter</code> should be used.
- *
- * Copied from Apache Commons IO revision 1681000.
+ *
+ * <h3>History</h3>
+ * <ol>
+ * <li>Copied from Apache Commons IO revision 1681000.</li>
+ * <li>Pick up Javadoc updates from revision 1722253.</li>
+ * <ol>
*/
public class StringBuilderWriter extends Writer implements Serializable {
@@ -36,14 +40,14 @@ public class StringBuilderWriter extends Writer implements Serializable {
private final StringBuilder builder;
/**
- * Construct a new {@link StringBuilder} instance with default capacity.
+ * Constructs a new {@link StringBuilder} instance with default capacity.
*/
public StringBuilderWriter() {
this.builder = new StringBuilder();
}
/**
- * Construct a new {@link StringBuilder} instance with the specified capacity.
+ * Constructs a new {@link StringBuilder} instance with the specified capacity.
*
* @param capacity The initial capacity of the underlying {@link StringBuilder}
*/
@@ -52,7 +56,7 @@ public class StringBuilderWriter extends Writer implements Serializable {
}
/**
- * Construct a new instance with the specified {@link StringBuilder}.
+ * Constructs a new instance with the specified {@link StringBuilder}.
*
* <p>If {@code builder} is null a new instance with default capacity will be created.</p>
*
@@ -63,7 +67,7 @@ public class StringBuilderWriter extends Writer implements Serializable {
}
/**
- * Append a single character to this Writer.
+ * Appends a single character to this Writer.
*
* @param value The character to append
* @return This writer instance
@@ -75,7 +79,7 @@ public class StringBuilderWriter extends Writer implements Serializable {
}
/**
- * Append a character sequence to this Writer.
+ * Appends a character sequence to this Writer.
*
* @param value The character to append
* @return This writer instance
@@ -87,7 +91,7 @@ public class StringBuilderWriter extends Writer implements Serializable {
}
/**
- * Append a portion of a character sequence to the {@link StringBuilder}.
+ * Appends a portion of a character sequence to the {@link StringBuilder}.
*
* @param value The character to append
* @param start The index of the first character
@@ -118,7 +122,7 @@ public class StringBuilderWriter extends Writer implements Serializable {
/**
- * Write a String to the {@link StringBuilder}.
+ * Writes a String to the {@link StringBuilder}.
*
* @param value The value to write
*/
@@ -130,7 +134,7 @@ public class StringBuilderWriter extends Writer implements Serializable {
}
/**
- * Write a portion of a character array to the {@link StringBuilder}.
+ * Writes a portion of a character array to the {@link StringBuilder}.
*
* @param value The value to write
* @param offset The index of the first character
@@ -144,7 +148,7 @@ public class StringBuilderWriter extends Writer implements Serializable {
}
/**
- * Return the underlying builder.
+ * Returns the underlying builder.
*
* @return The underlying builder
*/