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/08/17 13:22:06 UTC
[1/4] logging-log4j2 git commit: Fix comment
Repository: logging-log4j2
Updated Branches:
refs/heads/master b529739c0 -> 211274303
Fix comment
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/1cdccca7
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/1cdccca7
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/1cdccca7
Branch: refs/heads/master
Commit: 1cdccca74d59213f518f87a97ac488be2407fea6
Parents: b529739
Author: Mikael St�ldal <mi...@staldal.nu>
Authored: Wed Aug 17 14:00:57 2016 +0200
Committer: Mikael St�ldal <mi...@staldal.nu>
Committed: Wed Aug 17 14:00:57 2016 +0200
----------------------------------------------------------------------
.../java/org/apache/log4j/config/Log4j1ConfigurationFactory.java | 1 -
1 file changed, 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1cdccca7/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java b/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
index 0824fae..492ff7c 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
@@ -48,7 +48,6 @@ import org.apache.logging.log4j.status.StatusLogger;
* <li>log4j.logger</li>
* <li>log4j.appender</li>
* <li>org.apache.log4j.ConsoleAppender</li>
- * <li>org.apache.log4j.PatternLayout</li>
* <ul>
* <li>Follow</li>
* <li>Target</li>
[3/4] logging-log4j2 git commit: Support %properties in PatternLayout
Posted by mi...@apache.org.
Support %properties in PatternLayout
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/83c95761
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/83c95761
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/83c95761
Branch: refs/heads/master
Commit: 83c95761c218c530f3c09ad062d5f6141929c7ef
Parents: a3f2d50
Author: Mikael St�ldal <mi...@staldal.nu>
Authored: Wed Aug 17 15:00:10 2016 +0200
Committer: Mikael St�ldal <mi...@staldal.nu>
Committed: Wed Aug 17 15:00:10 2016 +0200
----------------------------------------------------------------------
.../config/Log4j1ConfigurationFactory.java | 7 +-
.../pattern/Log4j1MdcPatternConverter.java | 91 ++++++++++++++++++++
.../config/Log4j1ConfigurationFactoryTest.java | 2 +-
.../pattern/Log4j1MdcPatternConverterTest.java | 79 +++++++++++++++++
...g4j-console-EnhancedPatternLayout.properties | 2 +-
5 files changed, 175 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/83c95761/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java b/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
index 492ff7c..19acdaa 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
@@ -121,13 +121,12 @@ public class Log4j1ConfigurationFactory extends ConfigurationFactory {
case "org.apache.log4j.EnhancedPatternLayout": {
final String pattern = getLog4jAppenderValue(properties, name, "layout.ConversionPattern", null);
// TODO missing %ndc as alias for %NDC
- // TODO missing %properties as alias for %MDC
// TODO Log4j 2's PatternLayout's %x (NDC) is not compatible with Log4j 1's %x
// Log4j 1: "foo bar baz"
// Log4j 2: "[foo, bar, baz]"
- // TODO Log4j 2's PatternLayout's %X (MDC) is not compatible with Log4j 1's %X
- // Log4j 1: "{{foo,bar},{hoo,boo}}"
- // Log4j 2: "{foo=bar,hoo=boo}"
+ // Log4j 2's PatternLayout's %X (MDC) is not compatible with Log4j 1's %X
+ // Log4j 1: "{{foo,bar}{hoo,boo}}"
+ // Log4j 2: "{foo=bar,hoo=boo}"
appenderBuilder.add(newPatternLayout(builder, pattern));
break;
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/83c95761/log4j-1.2-api/src/main/java/org/apache/log4j/pattern/Log4j1MdcPatternConverter.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/pattern/Log4j1MdcPatternConverter.java b/log4j-1.2-api/src/main/java/org/apache/log4j/pattern/Log4j1MdcPatternConverter.java
new file mode 100644
index 0000000..c124551
--- /dev/null
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/pattern/Log4j1MdcPatternConverter.java
@@ -0,0 +1,91 @@
+/*
+ * 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.log4j.pattern;
+
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.pattern.ConverterKeys;
+import org.apache.logging.log4j.core.pattern.LogEventPatternConverter;
+import org.apache.logging.log4j.core.pattern.PatternConverter;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+/**
+ * Able to handle the contents of the LogEvent's MDC and either
+ * output the entire contents of the properties, or to output the value of a specific key
+ * within the property bundle when this pattern converter has the option set.
+ */
+@Plugin(name = "Log4j1MdcPatternConverter", category = PatternConverter.CATEGORY)
+@ConverterKeys({ "properties" })
+public final class Log4j1MdcPatternConverter extends LogEventPatternConverter {
+ /**
+ * Name of property to output.
+ */
+ private final String key;
+
+ /**
+ * Private constructor.
+ *
+ * @param options options, may be null.
+ */
+ private Log4j1MdcPatternConverter(final String[] options) {
+ super(options != null && options.length > 0 ? "Log4j1MDC{" + options[0] + '}' : "Log4j1MDC", "property");
+ if (options != null && options.length > 0) {
+ key = options[0];
+ } else {
+ key = null;
+ }
+ }
+
+ /**
+ * Obtains an instance of PropertiesPatternConverter.
+ *
+ * @param options options, may be null or first element contains name of property to format.
+ * @return instance of PropertiesPatternConverter.
+ */
+ public static Log4j1MdcPatternConverter newInstance(final String[] options) {
+ return new Log4j1MdcPatternConverter(options);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void format(final LogEvent event, final StringBuilder toAppendTo) {
+ final Map<String, String> contextMap = event.getContextMap();
+ if (key == null) {
+ // if there is no additional options, we output every single Key/Value pair for the MDC
+ toAppendTo.append('{');
+ if (contextMap != null && !contextMap.isEmpty()) {
+ final Set<String> eventKeys = new TreeSet<>(contextMap.keySet());
+ for (final String eventKey : eventKeys) {
+ toAppendTo.append('{').append(eventKey).append(',').append(contextMap.get(eventKey)).append('}');
+
+ }
+ }
+ toAppendTo.append('}');
+ } else {
+ // otherwise they just want a single key output
+ final Object val = contextMap.get(key);
+ if (val != null) {
+ toAppendTo.append(val);
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/83c95761/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java b/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
index 1ee78c5..51abd59 100644
--- a/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
+++ b/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
@@ -55,7 +55,7 @@ public class Log4j1ConfigurationFactoryTest {
@Test
public void testConsoleEnhancedPatternLayout() throws Exception {
final PatternLayout layout = (PatternLayout) testConsole("config-1.2/log4j-console-EnhancedPatternLayout.properties");
- assertEquals("%d{ISO8601} [%t][%c] %-5p: %m%n", layout.getConversionPattern());
+ assertEquals("%d{ISO8601} [%t][%c] %-5p %properties: %m%n", layout.getConversionPattern());
}
@Test
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/83c95761/log4j-1.2-api/src/test/java/org/apache/log4j/pattern/Log4j1MdcPatternConverterTest.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/pattern/Log4j1MdcPatternConverterTest.java b/log4j-1.2-api/src/test/java/org/apache/log4j/pattern/Log4j1MdcPatternConverterTest.java
new file mode 100644
index 0000000..32ac89f
--- /dev/null
+++ b/log4j-1.2-api/src/test/java/org/apache/log4j/pattern/Log4j1MdcPatternConverterTest.java
@@ -0,0 +1,79 @@
+/*
+ * 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.log4j.pattern;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.apache.logging.log4j.message.SimpleMessage;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+
+public class Log4j1MdcPatternConverterTest {
+
+ @Test
+ public void testConverter0() {
+ Map<String, String> contextMap = new HashMap<>(0);
+ String expected = "{}";
+ test(contextMap, expected, null);
+ }
+
+ @Test
+ public void testConverter1() {
+ Map<String, String> contextMap = new HashMap<>(1);
+ contextMap.put("key1", "value1");
+ String expected = "{{key1,value1}}";
+ test(contextMap, expected, null);
+ }
+
+ @Test
+ public void testConverter2() {
+ Map<String, String> contextMap = new HashMap<>(2);
+ contextMap.put("key1", "value1");
+ contextMap.put("key2", "value2");
+ String expected = "{{key1,value1}{key2,value2}}";
+ test(contextMap, expected, null);
+ }
+
+ @Test
+ public void testConverterWithKey() {
+ Map<String, String> contextMap = new HashMap<>(2);
+ contextMap.put("key1", "value1");
+ contextMap.put("key2", "value2");
+ String expected = "value1";
+ test(contextMap, expected, new String[] {"key1"});
+ }
+
+ private void test(Map<String, String> contextMap, String expected, String[] options) {
+ final LogEvent event = Log4jLogEvent.newBuilder()
+ .setLoggerName("MyLogger")
+ .setLevel(Level.DEBUG)
+ .setMessage(new SimpleMessage("Hello"))
+ .setContextMap(contextMap)
+ .build();
+ final StringBuilder sb = new StringBuilder();
+ final Log4j1MdcPatternConverter converter = Log4j1MdcPatternConverter.newInstance(options);
+ converter.format(event, sb);
+ assertEquals(expected, sb.toString());
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/83c95761/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-EnhancedPatternLayout.properties
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-EnhancedPatternLayout.properties b/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-EnhancedPatternLayout.properties
index ab61518..2a233f1 100644
--- a/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-EnhancedPatternLayout.properties
+++ b/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-EnhancedPatternLayout.properties
@@ -14,6 +14,6 @@ log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.ImmediateFlush=false
log4j.appender.Console.Target=System.err
log4j.appender.Console.layout=org.apache.log4j.EnhancedPatternLayout
-log4j.appender.Console.layout.ConversionPattern=%d{ISO8601} [%t][%c] %-5p: %m%n
+log4j.appender.Console.layout.ConversionPattern=%d{ISO8601} [%t][%c] %-5p %properties: %m%n
log4j.logger.com.example.foo = DEBUG
[4/4] logging-log4j2 git commit: Support %ndc in PatternLayout
Posted by mi...@apache.org.
Support %ndc in PatternLayout
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/21127430
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/21127430
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/21127430
Branch: refs/heads/master
Commit: 211274303961cf0df8ddfd2860f0570af5ed7c6c
Parents: 83c9576
Author: Mikael St�ldal <mi...@staldal.nu>
Authored: Wed Aug 17 15:21:31 2016 +0200
Committer: Mikael St�ldal <mi...@staldal.nu>
Committed: Wed Aug 17 15:21:31 2016 +0200
----------------------------------------------------------------------
.../config/Log4j1ConfigurationFactory.java | 34 +++------
.../pattern/Log4j1NdcPatternConverter.java | 63 +++++++++++++++++
.../config/Log4j1ConfigurationFactoryTest.java | 2 +-
.../pattern/Log4j1NdcPatternConverterTest.java | 74 ++++++++++++++++++++
...g4j-console-EnhancedPatternLayout.properties | 2 +-
5 files changed, 150 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/21127430/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java b/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
index 19acdaa..427f57f 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
@@ -51,13 +51,7 @@ import org.apache.logging.log4j.status.StatusLogger;
* <ul>
* <li>Follow</li>
* <li>Target</li>
- * <li>layout = org.apache.log4j.PatternLayout (partial)</li>
- * <li>layout = org.apache.log4j.EnhancedPatternLayout (partial)</li>
- * <li>layout = org.apache.log4j.SimpleLayout</li>
- * <li>layout = org.apache.log4j.TTCCLayout</li>
- * <li>layout = org.apache.log4j.HTMLLayout</li>
- * <li>layout = org.apache.log4j.xml.XMLLayout</li>
- * <li>layout.ConversionPattern</li>
+ * <li>layout</li>
* </ul>
* </ul>
*/
@@ -107,26 +101,20 @@ public class Log4j1ConfigurationFactory extends ConfigurationFactory {
final String layoutValue = getLog4jAppenderValue(properties, name, "layout", null);
if (layoutValue != null) {
switch (layoutValue) {
- case "org.apache.log4j.PatternLayout": {
- final String pattern = getLog4jAppenderValue(properties, name, "layout.ConversionPattern", null);
- // TODO Log4j 2's PatternLayout's %x (NDC) is not compatible with Log4j 1's %x
- // Log4j 1: "foo bar baz"
- // Log4j 2: "[foo, bar, baz]"
- // TODO Log4j 2's PatternLayout's %X (MDC) is not compatible with Log4j 1's %X
- // Log4j 1: "{{foo,bar},{hoo,boo}}"
- // Log4j 2: "{foo=bar,hoo=boo}"
- appenderBuilder.add(newPatternLayout(builder, pattern));
- break;
- }
+ case "org.apache.log4j.PatternLayout":
case "org.apache.log4j.EnhancedPatternLayout": {
final String pattern = getLog4jAppenderValue(properties, name, "layout.ConversionPattern", null);
- // TODO missing %ndc as alias for %NDC
- // TODO Log4j 2's PatternLayout's %x (NDC) is not compatible with Log4j 1's %x
- // Log4j 1: "foo bar baz"
- // Log4j 2: "[foo, bar, baz]"
- // Log4j 2's PatternLayout's %X (MDC) is not compatible with Log4j 1's %X
+
+ // Log4j 2's %x (NDC) is not compatible with Log4j 1's %x
+ // Log4j 1: "foo bar baz"
+ // Log4j 2: "[foo, bar, baz]"
+ // Use %ndc to get the Log4j 1 format
+
+ // Log4j 2's %X (MDC) is not compatible with Log4j 1's %X
// Log4j 1: "{{foo,bar}{hoo,boo}}"
// Log4j 2: "{foo=bar,hoo=boo}"
+ // Use %properties to get the Log4j 1 format
+
appenderBuilder.add(newPatternLayout(builder, pattern));
break;
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/21127430/log4j-1.2-api/src/main/java/org/apache/log4j/pattern/Log4j1NdcPatternConverter.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/pattern/Log4j1NdcPatternConverter.java b/log4j-1.2-api/src/main/java/org/apache/log4j/pattern/Log4j1NdcPatternConverter.java
new file mode 100644
index 0000000..d3f16f5
--- /dev/null
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/pattern/Log4j1NdcPatternConverter.java
@@ -0,0 +1,63 @@
+/*
+ * 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.log4j.pattern;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.pattern.ConverterKeys;
+import org.apache.logging.log4j.core.pattern.LogEventPatternConverter;
+import org.apache.logging.log4j.core.pattern.PatternConverter;
+
+import java.util.List;
+
+
+/**
+ * Returns the event's NDC in a StringBuilder.
+ */
+@Plugin(name = "Log4j1NdcPatternConverter", category = PatternConverter.CATEGORY)
+@ConverterKeys({ "ndc" })
+public final class Log4j1NdcPatternConverter extends LogEventPatternConverter {
+ /**
+ * Singleton.
+ */
+ private static final Log4j1NdcPatternConverter INSTANCE =
+ new Log4j1NdcPatternConverter();
+
+ /**
+ * Private constructor.
+ */
+ private Log4j1NdcPatternConverter() {
+ super("Log4j1NDC", "ndc");
+ }
+
+ /**
+ * Obtains an instance of NdcPatternConverter.
+ *
+ * @param options options, may be null.
+ * @return instance of NdcPatternConverter.
+ */
+ public static Log4j1NdcPatternConverter newInstance(final String[] options) {
+ return INSTANCE;
+ }
+
+ @Override
+ public void format(final LogEvent event, final StringBuilder toAppendTo) {
+ List<String> ndc = event.getContextStack().asList();
+ toAppendTo.append(StringUtils.join(ndc, ' '));
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/21127430/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java b/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
index 51abd59..87fb70b 100644
--- a/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
+++ b/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
@@ -55,7 +55,7 @@ public class Log4j1ConfigurationFactoryTest {
@Test
public void testConsoleEnhancedPatternLayout() throws Exception {
final PatternLayout layout = (PatternLayout) testConsole("config-1.2/log4j-console-EnhancedPatternLayout.properties");
- assertEquals("%d{ISO8601} [%t][%c] %-5p %properties: %m%n", layout.getConversionPattern());
+ assertEquals("%d{ISO8601} [%t][%c] %-5p %properties %ndc: %m%n", layout.getConversionPattern());
}
@Test
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/21127430/log4j-1.2-api/src/test/java/org/apache/log4j/pattern/Log4j1NdcPatternConverterTest.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/pattern/Log4j1NdcPatternConverterTest.java b/log4j-1.2-api/src/test/java/org/apache/log4j/pattern/Log4j1NdcPatternConverterTest.java
new file mode 100644
index 0000000..2f0b80f
--- /dev/null
+++ b/log4j-1.2-api/src/test/java/org/apache/log4j/pattern/Log4j1NdcPatternConverterTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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.log4j.pattern;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.ThreadContext;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.apache.logging.log4j.junit.ThreadContextStackRule;
+import org.apache.logging.log4j.message.SimpleMessage;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class Log4j1NdcPatternConverterTest {
+
+ @Rule
+ public final ThreadContextStackRule threadContextRule = new ThreadContextStackRule();
+
+ @Test
+ public void testEmpty() {
+ testConverter("");
+ }
+
+ @Test
+ public void test1() {
+ ThreadContext.push("foo");
+ testConverter("foo");
+ }
+
+ @Test
+ public void test2() {
+ ThreadContext.push("foo");
+ ThreadContext.push("bar");
+ testConverter("foo bar");
+ }
+
+ @Test
+ public void test3() {
+ ThreadContext.push("foo");
+ ThreadContext.push("bar");
+ ThreadContext.push("baz");
+ testConverter("foo bar baz");
+ }
+
+ private void testConverter(final String expected) {
+ final Log4j1NdcPatternConverter converter = Log4j1NdcPatternConverter.newInstance(null);
+ final LogEvent event = Log4jLogEvent.newBuilder()
+ .setLoggerName("MyLogger")
+ .setLevel(Level.DEBUG)
+ .setMessage(new SimpleMessage("Hello"))
+ .build();
+ final StringBuilder sb = new StringBuilder();
+ converter.format(event, sb);
+ assertEquals(expected, sb.toString());
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/21127430/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-EnhancedPatternLayout.properties
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-EnhancedPatternLayout.properties b/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-EnhancedPatternLayout.properties
index 2a233f1..d8099f6 100644
--- a/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-EnhancedPatternLayout.properties
+++ b/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-EnhancedPatternLayout.properties
@@ -14,6 +14,6 @@ log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.ImmediateFlush=false
log4j.appender.Console.Target=System.err
log4j.appender.Console.layout=org.apache.log4j.EnhancedPatternLayout
-log4j.appender.Console.layout.ConversionPattern=%d{ISO8601} [%t][%c] %-5p %properties: %m%n
+log4j.appender.Console.layout.ConversionPattern=%d{ISO8601} [%t][%c] %-5p %properties %ndc: %m%n
log4j.logger.com.example.foo = DEBUG
[2/4] logging-log4j2 git commit: Fix comment
Posted by mi...@apache.org.
Fix comment
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/a3f2d50a
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/a3f2d50a
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/a3f2d50a
Branch: refs/heads/master
Commit: a3f2d50a6abbaa355977753e4905bc86f975c563
Parents: 1cdccca
Author: Mikael St�ldal <mi...@staldal.nu>
Authored: Wed Aug 17 14:04:40 2016 +0200
Committer: Mikael St�ldal <mi...@staldal.nu>
Committed: Wed Aug 17 14:04:40 2016 +0200
----------------------------------------------------------------------
.../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/a3f2d50a/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 897be86..4f77649 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
@@ -84,7 +84,7 @@ public final class PatternLayout extends AbstractStringLayout {
private final Serializer eventSerializer;
/**
- * Constructs a EnhancedPatternLayout using the supplied conversion pattern.
+ * Constructs a PatternLayout using the supplied conversion pattern.
*
* @param config The Configuration.
* @param replace The regular expression to match.