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/14 20:16:59 UTC

[01/11] logging-log4j2 git commit: Test for NdcPatternConverter

Repository: logging-log4j2
Updated Branches:
  refs/heads/LOG4J2-1512 0e86947b0 -> 04ac7e2ae


Test for NdcPatternConverter


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/f32c0fe1
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/f32c0fe1
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/f32c0fe1

Branch: refs/heads/LOG4J2-1512
Commit: f32c0fe1e4828bac120ab2554d761affbef8b4aa
Parents: c0cb21e
Author: Mikael St�ldal <mi...@staldal.nu>
Authored: Sat Aug 13 18:56:59 2016 +0200
Committer: Mikael St�ldal <mi...@staldal.nu>
Committed: Sat Aug 13 18:56:59 2016 +0200

----------------------------------------------------------------------
 .../core/pattern/NdcPatternConverterTest.java   | 77 ++++++++++++++++++++
 1 file changed, 77 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f32c0fe1/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/NdcPatternConverterTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/NdcPatternConverterTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/NdcPatternConverterTest.java
new file mode 100644
index 0000000..85b3e85
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/NdcPatternConverterTest.java
@@ -0,0 +1,77 @@
+/*
+ * 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.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.message.Message;
+import org.apache.logging.log4j.message.SimpleMessage;
+import org.junit.After;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class NdcPatternConverterTest {
+
+    @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 Message msg = new SimpleMessage("Hello");
+        final NdcPatternConverter converter = NdcPatternConverter.newInstance(null);
+        final LogEvent event = Log4jLogEvent.newBuilder() //
+                .setLoggerName("MyLogger") //
+                .setLevel(Level.DEBUG) //
+                .setMessage(msg) //
+                .build();
+        final StringBuilder sb = new StringBuilder();
+        converter.format(event, sb);
+        final String str = sb.toString();
+        assertEquals(expected, str);
+    }
+
+    @After
+    public void tearDown() {
+        ThreadContext.clearStack();
+    }
+}
+


[02/11] logging-log4j2 git commit: Clear ThreadContext after test

Posted by mi...@apache.org.
Clear ThreadContext after test


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/a40b28f2
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/a40b28f2
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/a40b28f2

Branch: refs/heads/LOG4J2-1512
Commit: a40b28f26901c5549810d36fa6763a8697207740
Parents: f32c0fe
Author: Mikael St�ldal <mi...@staldal.nu>
Authored: Sat Aug 13 19:00:47 2016 +0200
Committer: Mikael St�ldal <mi...@staldal.nu>
Committed: Sat Aug 13 19:00:47 2016 +0200

----------------------------------------------------------------------
 .../core/pattern/MdcPatternConverterTest.java   | 26 +++++++++++---------
 1 file changed, 14 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a40b28f2/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/MdcPatternConverterTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/MdcPatternConverterTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/MdcPatternConverterTest.java
index dcacbcf..abdae00 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/MdcPatternConverterTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/MdcPatternConverterTest.java
@@ -22,6 +22,8 @@ import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.impl.Log4jLogEvent;
 import org.apache.logging.log4j.message.Message;
 import org.apache.logging.log4j.message.SimpleMessage;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
 
 import static org.junit.Assert.*;
@@ -31,13 +33,16 @@ import static org.junit.Assert.*;
  */
 public class MdcPatternConverterTest {
 
-    @Test
-    public void testConverter() {
-
-        final Message msg = new SimpleMessage("Hello");
+    @Before
+    public void setup() {
         ThreadContext.put("subject", "I");
         ThreadContext.put("verb", "love");
         ThreadContext.put("object", "Log4j");
+    }
+
+    @Test
+    public void testConverter() {
+        final Message msg = new SimpleMessage("Hello");
         final MdcPatternConverter converter = MdcPatternConverter.newInstance(null);
         final LogEvent event = Log4jLogEvent.newBuilder() //
                 .setLoggerName("MyLogger") //
@@ -53,12 +58,8 @@ public class MdcPatternConverterTest {
 
     @Test
     public void testConverterWithKey() {
-
         final Message msg = new SimpleMessage("Hello");
         final String [] options = new String[] {"object"};
-        ThreadContext.put("subject", "I");
-        ThreadContext.put("verb", "love");
-        ThreadContext.put("object", "Log4j");
         final MdcPatternConverter converter = MdcPatternConverter.newInstance(options);
         final LogEvent event = Log4jLogEvent.newBuilder() //
                 .setLoggerName("MyLogger") //
@@ -74,12 +75,8 @@ public class MdcPatternConverterTest {
 
     @Test
     public void testConverterWithKeys() {
-
         final Message msg = new SimpleMessage("Hello");
         final String [] options = new String[] {"object, subject"};
-        ThreadContext.put("subject", "I");
-        ThreadContext.put("verb", "love");
-        ThreadContext.put("object", "Log4j");
         final MdcPatternConverter converter = MdcPatternConverter.newInstance(options);
         final LogEvent event = Log4jLogEvent.newBuilder() //
                 .setLoggerName("MyLogger") //
@@ -92,5 +89,10 @@ public class MdcPatternConverterTest {
         final String expected = "{object=Log4j, subject=I}";
         assertEquals(expected, str);
     }
+
+    @After
+    public void tearDown() {
+        ThreadContext.clearStack();
+    }
 }
 


[11/11] logging-log4j2 git commit: Merge branch 'master' into LOG4J2-1512

Posted by mi...@apache.org.
Merge branch 'master' into LOG4J2-1512


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/04ac7e2a
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/04ac7e2a
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/04ac7e2a

Branch: refs/heads/LOG4J2-1512
Commit: 04ac7e2ae7376026bd13e0c6939954d040f3bb78
Parents: 0e86947 8e01bde
Author: Mikael St�ldal <mi...@staldal.nu>
Authored: Sun Aug 14 22:16:39 2016 +0200
Committer: Mikael St�ldal <mi...@staldal.nu>
Committed: Sun Aug 14 22:16:39 2016 +0200

----------------------------------------------------------------------
 log4j-1.2-api/pom.xml                           |   4 +
 .../config/Log4j1ConfigurationFactory.java      |  32 ++++--
 .../apache/log4j/layout/Log4j1XmlLayout.java    | 104 +++++++++++++++++++
 .../org/apache/log4j/layout/TTCCLayout.java     |  99 ++++++++++++++++++
 .../config/Log4j1ConfigurationFactoryTest.java  |  13 +--
 .../log4j/layout/Log4j1XmlLayoutTest.java       |  48 +++++++++
 .../org/apache/log4j/layout/TTCCLayoutTest.java |  82 +++++++++++++++
 .../log4j-console-XmlLayout.properties          |   2 +-
 .../core/pattern/MdcPatternConverterTest.java   |  26 ++---
 .../core/pattern/NdcPatternConverterTest.java   |  77 ++++++++++++++
 10 files changed, 459 insertions(+), 28 deletions(-)
----------------------------------------------------------------------



[06/11] logging-log4j2 git commit: Add TODOs

Posted by mi...@apache.org.
Add TODOs


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/f91916a0
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/f91916a0
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/f91916a0

Branch: refs/heads/LOG4J2-1512
Commit: f91916a07f379de9df4c09127a2e1f5957d322e7
Parents: ab0ae6a
Author: Mikael St�ldal <mi...@staldal.nu>
Authored: Sat Aug 13 22:07:36 2016 +0200
Committer: Mikael St�ldal <mi...@staldal.nu>
Committed: Sat Aug 13 22:07:36 2016 +0200

----------------------------------------------------------------------
 .../config/Log4j1ConfigurationFactory.java      | 27 +++++++++++++-------
 1 file changed, 18 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f91916a0/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 5438d3b..020da5e 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
@@ -52,10 +52,10 @@ import org.apache.logging.log4j.status.StatusLogger;
  * <ul>
  * <li>Follow</li>
  * <li>Target</li>
- * <li>layout = org.apache.log4j.PatternLayout</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.PatternLayout (partial)</li>
+ * <li>layout = org.apache.log4j.EnhancedPatternLayout (partial)</li>
+ * <li>layout = org.apache.log4j.SimpleLayout (complete)</li>
+ * <li>layout = org.apache.log4j.TTCCLayout (complete)</li>
  * <li>layout = org.apache.log4j.HTMLLayout (partial)</li>
  * <li>layout = org.apache.log4j.xml.XMLLayout (partial)</li>
  * <li>layout.ConversionPattern</li>
@@ -110,15 +110,24 @@ public class Log4j1ConfigurationFactory extends ConfigurationFactory {
             final String cpValue = getLog4jAppenderValue(properties, name, "layout.ConversionPattern", null);
             switch (layoutValue) {
             case "org.apache.log4j.PatternLayout": {
-                // TODO We do not have a %d for the time since the start of the app?
-
-                // TODO Log4j 2's PatternLayout's %NDC is not compatible with Log4j 1's
+                // 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, cpValue));
                 break;
             }
             case "org.apache.log4j.EnhancedPatternLayout": {
+                // 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}"
                 appenderBuilder.add(newPatternLayout(builder, cpValue));
                 break;
             }
@@ -131,11 +140,11 @@ public class Log4j1ConfigurationFactory extends ConfigurationFactory {
                 break;
             }
             case "org.apache.log4j.HTMLLayout": {
-                appenderBuilder.add(builder.newLayout("HtmlLayout"));
+                appenderBuilder.add(builder.newLayout("HtmlLayout")); // TODO check if compatible
                 break;
             }
             case "org.apache.log4j.xml.XMLLayout": {
-                appenderBuilder.add(builder.newLayout("XmlLayout"));
+                appenderBuilder.add(builder.newLayout("XmlLayout")); // TODO check if compatible
                 break;
             }
             default:


[09/11] logging-log4j2 git commit: Fix comments

Posted by mi...@apache.org.
Fix comments


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/f511f848
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/f511f848
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/f511f848

Branch: refs/heads/LOG4J2-1512
Commit: f511f848cf9dc8d52210f8ee12ab914bd21176e3
Parents: 2642fff
Author: Mikael St�ldal <mi...@staldal.nu>
Authored: Sun Aug 14 11:20:16 2016 +0200
Committer: Mikael St�ldal <mi...@staldal.nu>
Committed: Sun Aug 14 11:20:16 2016 +0200

----------------------------------------------------------------------
 .../org/apache/log4j/config/Log4j1ConfigurationFactory.java  | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f511f848/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 396d6b1..d351897 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
@@ -54,9 +54,9 @@ import org.apache.logging.log4j.status.StatusLogger;
  * <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 (complete)</li>
- * <li>layout = org.apache.log4j.TTCCLayout (complete)</li>
- * <li>layout = org.apache.log4j.HTMLLayout (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.ConversionPattern</li>
  * </ul>
  * </ul>
@@ -139,7 +139,7 @@ public class Log4j1ConfigurationFactory extends ConfigurationFactory {
                 break;
             }
             case "org.apache.log4j.HTMLLayout": {
-                appenderBuilder.add(builder.newLayout("HtmlLayout")); // TODO check if compatible
+                appenderBuilder.add(builder.newLayout("HtmlLayout"));
                 break;
             }
             case "org.apache.log4j.xml.XMLLayout": {


[04/11] logging-log4j2 git commit: Fix Layouts

Posted by mi...@apache.org.
Fix Layouts


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/526946eb
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/526946eb
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/526946eb

Branch: refs/heads/LOG4J2-1512
Commit: 526946eb56e2658228190f8b5862bd131d09e627
Parents: b06d5de
Author: Mikael St�ldal <mi...@staldal.nu>
Authored: Sat Aug 13 19:23:18 2016 +0200
Committer: Mikael St�ldal <mi...@staldal.nu>
Committed: Sat Aug 13 19:24:05 2016 +0200

----------------------------------------------------------------------
 .../org/apache/log4j/config/Log4j1ConfigurationFactory.java   | 7 ++++---
 .../resources/config-1.2/log4j-console-XmlLayout.properties   | 2 +-
 2 files changed, 5 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/526946eb/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 fd509e0..fc49c2b 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
@@ -53,10 +53,11 @@ import org.apache.logging.log4j.status.StatusLogger;
  * <li>Follow</li>
  * <li>Target</li>
  * <li>layout = org.apache.log4j.PatternLayout</li>
+ * <li>layout = org.apache.log4j.EnhancedPatternLayout (partial?)</li>
  * <li>layout = org.apache.log4j.SimpleLayout</li>
  * <li>layout = org.apache.log4j.TTCCLayout (partial)</li>
- * <li>layout = org.apache.log4j.HtmlLayout (partial)</li>
- * <li>layout = org.apache.log4j.XmlLayout (partial)</li>
+ * <li>layout = org.apache.log4j.HTMLLayout (partial)</li>
+ * <li>layout = org.apache.log4j.xml.XMLLayout (partial)</li>
  * <li>layout.ConversionPattern</li>
  * </ul>
  * </ul>
@@ -133,7 +134,7 @@ public class Log4j1ConfigurationFactory extends ConfigurationFactory {
                 appenderBuilder.add(builder.newLayout("HtmlLayout"));
                 break;
             }
-            case "org.apache.log4j.XMLLayout": {
+            case "org.apache.log4j.xml.XMLLayout": {
                 appenderBuilder.add(builder.newLayout("XmlLayout"));
                 break;
             }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/526946eb/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-XmlLayout.properties
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-XmlLayout.properties b/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-XmlLayout.properties
index 155b1ff..ab1c53b 100644
--- a/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-XmlLayout.properties
+++ b/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-XmlLayout.properties
@@ -13,6 +13,6 @@ log4j.rootLogger=TRACE, Console
 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.XMLLayout
+log4j.appender.Console.layout=org.apache.log4j.xml.XMLLayout
 
 log4j.logger.com.example.foo = DEBUG


[07/11] logging-log4j2 git commit: Fix test clean-up

Posted by mi...@apache.org.
Fix test clean-up


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/d219411e
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/d219411e
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/d219411e

Branch: refs/heads/LOG4J2-1512
Commit: d219411e6834340cc4434e350e23e3f437a89b76
Parents: f91916a
Author: Mikael St�ldal <mi...@staldal.nu>
Authored: Sun Aug 14 10:59:06 2016 +0200
Committer: Mikael St�ldal <mi...@staldal.nu>
Committed: Sun Aug 14 10:59:06 2016 +0200

----------------------------------------------------------------------
 .../apache/logging/log4j/core/pattern/MdcPatternConverterTest.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d219411e/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/MdcPatternConverterTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/MdcPatternConverterTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/MdcPatternConverterTest.java
index abdae00..c96f200 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/MdcPatternConverterTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/MdcPatternConverterTest.java
@@ -92,7 +92,7 @@ public class MdcPatternConverterTest {
 
     @After
     public void tearDown() {
-        ThreadContext.clearStack();
+        ThreadContext.clearMap();
     }
 }
 


[08/11] logging-log4j2 git commit: Do not try to use Log4j 2 XmlLayout in place of Log4j 1 XmlLayout

Posted by mi...@apache.org.
Do not try to use Log4j 2 XmlLayout in place of Log4j 1 XmlLayout


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/2642fff4
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/2642fff4
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/2642fff4

Branch: refs/heads/LOG4J2-1512
Commit: 2642fff465ac5d0523d33a1af3c6b8a5a10a3ade
Parents: d219411
Author: Mikael St�ldal <mi...@staldal.nu>
Authored: Sun Aug 14 11:09:40 2016 +0200
Committer: Mikael St�ldal <mi...@staldal.nu>
Committed: Sun Aug 14 11:09:40 2016 +0200

----------------------------------------------------------------------
 .../org/apache/log4j/config/Log4j1ConfigurationFactory.java    | 6 +++---
 .../apache/log4j/config/Log4j1ConfigurationFactoryTest.java    | 3 ++-
 2 files changed, 5 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2642fff4/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 020da5e..396d6b1 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
@@ -57,7 +57,6 @@ import org.apache.logging.log4j.status.StatusLogger;
  * <li>layout = org.apache.log4j.SimpleLayout (complete)</li>
  * <li>layout = org.apache.log4j.TTCCLayout (complete)</li>
  * <li>layout = org.apache.log4j.HTMLLayout (partial)</li>
- * <li>layout = org.apache.log4j.xml.XMLLayout (partial)</li>
  * <li>layout.ConversionPattern</li>
  * </ul>
  * </ul>
@@ -144,11 +143,12 @@ public class Log4j1ConfigurationFactory extends ConfigurationFactory {
                 break;
             }
             case "org.apache.log4j.xml.XMLLayout": {
-                appenderBuilder.add(builder.newLayout("XmlLayout")); // TODO check if compatible
+                // We cannot use the XmlLayout in Log4j 2 since it has a significantly different format
+                reportWarning("Log4j 1 XMLLayout is not supported");
                 break;
             }
             default:
-                reportWarning("Unsupported value for console appender layout: " + layoutValue);
+                reportWarning("Unsupported layout: " + layoutValue);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2642fff4/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 e4330ca..48a154d 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
@@ -29,6 +29,7 @@ import org.apache.logging.log4j.core.layout.HtmlLayout;
 import org.apache.logging.log4j.core.layout.PatternLayout;
 import org.apache.logging.log4j.core.layout.XmlLayout;
 import org.junit.Assert;
+import org.junit.Ignore;
 import org.junit.Test;
 
 public class Log4j1ConfigurationFactoryTest {
@@ -81,7 +82,7 @@ public class Log4j1ConfigurationFactoryTest {
         Assert.assertTrue(layout instanceof TTCCLayout);
     }
 
-    @Test
+    @Ignore("XmlLayout not supported")
     public void testConsoleXmlLayout() throws Exception {
         final Layout<?> layout = testConsole("config-1.2/log4j-console-XmlLayout.properties");
         Assert.assertTrue(layout instanceof XmlLayout);


[03/11] logging-log4j2 git commit: Add TODO

Posted by mi...@apache.org.
Add TODO


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/b06d5de7
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/b06d5de7
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/b06d5de7

Branch: refs/heads/LOG4J2-1512
Commit: b06d5de75d22c3dc23d100f90538ff72bb1ec067
Parents: a40b28f
Author: Mikael St�ldal <mi...@staldal.nu>
Authored: Sat Aug 13 19:13:00 2016 +0200
Committer: Mikael St�ldal <mi...@staldal.nu>
Committed: Sat Aug 13 19:13:00 2016 +0200

----------------------------------------------------------------------
 .../java/org/apache/log4j/config/Log4j1ConfigurationFactory.java | 4 ++++
 1 file changed, 4 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b06d5de7/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 578b2ab..fd509e0 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
@@ -122,6 +122,10 @@ public class Log4j1ConfigurationFactory extends ConfigurationFactory {
             }
             case "org.apache.log4j.TTCCLayout": {
                 // TODO We do not have a %d for the time since the start of the app?
+
+                // TODO We miss the NDC here, and the Log4j 2's PatternLayout's %NDC is not compatible with Log4j 1's
+                //      Log4j 1: "foo bar baz"
+                //      Log4j 2: "[foo, bar, baz]"
                 appenderBuilder.add(newPatternLayout(builder, "%relative [%threadName] %level %logger - %m%n"));
                 break;
             }


[05/11] logging-log4j2 git commit: TTCCLayout for Log4j 1.x compatibility

Posted by mi...@apache.org.
TTCCLayout for Log4j 1.x compatibility


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/ab0ae6a7
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/ab0ae6a7
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/ab0ae6a7

Branch: refs/heads/LOG4J2-1512
Commit: ab0ae6a78224da0012aef53402f57161b7b23a1d
Parents: 526946e
Author: Mikael St�ldal <mi...@staldal.nu>
Authored: Sat Aug 13 21:24:33 2016 +0200
Committer: Mikael St�ldal <mi...@staldal.nu>
Committed: Sat Aug 13 21:24:33 2016 +0200

----------------------------------------------------------------------
 .../config/Log4j1ConfigurationFactory.java      | 14 +--
 .../org/apache/log4j/layout/TTCCLayout.java     | 99 ++++++++++++++++++++
 .../config/Log4j1ConfigurationFactoryTest.java  |  5 +-
 .../org/apache/log4j/layout/TTCCLayoutTest.java | 82 ++++++++++++++++
 4 files changed, 191 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ab0ae6a7/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 fc49c2b..5438d3b 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
@@ -55,7 +55,7 @@ import org.apache.logging.log4j.status.StatusLogger;
  * <li>layout = org.apache.log4j.PatternLayout</li>
  * <li>layout = org.apache.log4j.EnhancedPatternLayout (partial?)</li>
  * <li>layout = org.apache.log4j.SimpleLayout</li>
- * <li>layout = org.apache.log4j.TTCCLayout (partial)</li>
+ * <li>layout = org.apache.log4j.TTCCLayout</li>
  * <li>layout = org.apache.log4j.HTMLLayout (partial)</li>
  * <li>layout = org.apache.log4j.xml.XMLLayout (partial)</li>
  * <li>layout.ConversionPattern</li>
@@ -110,6 +110,11 @@ public class Log4j1ConfigurationFactory extends ConfigurationFactory {
             final String cpValue = getLog4jAppenderValue(properties, name, "layout.ConversionPattern", null);
             switch (layoutValue) {
             case "org.apache.log4j.PatternLayout": {
+                // TODO We do not have a %d for the time since the start of the app?
+
+                // TODO Log4j 2's PatternLayout's %NDC is not compatible with Log4j 1's
+                //      Log4j 1: "foo bar baz"
+                //      Log4j 2: "[foo, bar, baz]"
                 appenderBuilder.add(newPatternLayout(builder, cpValue));
                 break;
             }
@@ -122,12 +127,7 @@ public class Log4j1ConfigurationFactory extends ConfigurationFactory {
                 break;
             }
             case "org.apache.log4j.TTCCLayout": {
-                // TODO We do not have a %d for the time since the start of the app?
-
-                // TODO We miss the NDC here, and the Log4j 2's PatternLayout's %NDC is not compatible with Log4j 1's
-                //      Log4j 1: "foo bar baz"
-                //      Log4j 2: "[foo, bar, baz]"
-                appenderBuilder.add(newPatternLayout(builder, "%relative [%threadName] %level %logger - %m%n"));
+                appenderBuilder.add(builder.newLayout("TTCCLayout"));
                 break;
             }
             case "org.apache.log4j.HTMLLayout": {

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ab0ae6a7/log4j-1.2-api/src/main/java/org/apache/log4j/layout/TTCCLayout.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/layout/TTCCLayout.java b/log4j-1.2-api/src/main/java/org/apache/log4j/layout/TTCCLayout.java
new file mode 100644
index 0000000..53bd6db
--- /dev/null
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/layout/TTCCLayout.java
@@ -0,0 +1,99 @@
+/*
+ * 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.layout;
+
+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.PluginFactory;
+import org.apache.logging.log4j.core.layout.AbstractStringLayout;
+import org.apache.logging.log4j.core.layout.ByteBufferDestination;
+import org.apache.logging.log4j.core.util.Constants;
+import org.apache.logging.log4j.message.Message;
+import org.apache.logging.log4j.util.StringBuilderFormattable;
+
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+
+/**
+ * Port of TTCCLayout in Log4j 1.x. Provided for compatibility with existing Log4j 1 configurations.
+ *
+ * Originally developed by Ceki G&uuml;lc&uuml;, Heinz Richter, Christopher Williams, Mathias Bogaert.
+ */
+@Plugin(name = "TTCCLayout", category = Node.CATEGORY, elementType = Layout.ELEMENT_TYPE, printObject = true)
+public final class TTCCLayout extends AbstractStringLayout {
+
+    final long startTime = System.currentTimeMillis();
+
+    @PluginFactory
+    public static TTCCLayout createLayout() {
+        return new TTCCLayout();
+    }
+
+    private TTCCLayout() {
+        super(StandardCharsets.UTF_8);
+    }
+
+    @Override
+    public void encode(final LogEvent event, final ByteBufferDestination destination) {
+        final StringBuilder text = getStringBuilder();
+        formatTo(event, text);
+        getStringBuilderEncoder().encode(text, destination);
+    }
+
+    @Override
+    public String toSerializable(final LogEvent event) {
+        final StringBuilder text = getStringBuilder();
+        formatTo(event, text);
+        return text.toString();
+    }
+
+    private void formatTo(final LogEvent event, final StringBuilder buf) {
+        buf.append(event.getTimeMillis() - startTime);
+        buf.append(' ');
+
+        buf.append('[');
+        buf.append(event.getThreadName());
+        buf.append("] ");
+
+        buf.append(event.getLevel().toString());
+        buf.append(' ');
+
+        buf.append(event.getLoggerName());
+        buf.append(' ');
+
+        List<String> ndc = event.getContextStack().asList();
+        if (!ndc.isEmpty()) {
+            for (String ndcElement : ndc) {
+                buf.append(ndcElement);
+                buf.append(' ');
+            }
+        }
+
+        buf.append("- ");
+        final Message message = event.getMessage();
+        if (message instanceof StringBuilderFormattable) {
+            ((StringBuilderFormattable)message).formatTo(buf);
+        } else {
+            buf.append(message.getFormattedMessage());
+        }
+
+        buf.append(Constants.LINE_SEPARATOR);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ab0ae6a7/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 4d637b2..e4330ca 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
@@ -18,6 +18,7 @@ package org.apache.log4j.config;
 
 import java.net.URL;
 
+import org.apache.log4j.layout.TTCCLayout;
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.core.Layout;
 import org.apache.logging.log4j.core.appender.ConsoleAppender;
@@ -76,8 +77,8 @@ public class Log4j1ConfigurationFactoryTest {
 
     @Test
     public void testConsoleTtccLayout() throws Exception {
-        final PatternLayout layout = (PatternLayout) testConsole("config-1.2/log4j-console-TTCCLayout.properties");
-        Assert.assertEquals("%relative [%threadName] %level %logger - %m%n", layout.getConversionPattern());
+        final Layout<?> layout = testConsole("config-1.2/log4j-console-TTCCLayout.properties");
+        Assert.assertTrue(layout instanceof TTCCLayout);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ab0ae6a7/log4j-1.2-api/src/test/java/org/apache/log4j/layout/TTCCLayoutTest.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/layout/TTCCLayoutTest.java b/log4j-1.2-api/src/test/java/org/apache/log4j/layout/TTCCLayoutTest.java
new file mode 100644
index 0000000..1f548a8
--- /dev/null
+++ b/log4j-1.2-api/src/test/java/org/apache/log4j/layout/TTCCLayoutTest.java
@@ -0,0 +1,82 @@
+/*
+ * 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.layout;
+
+import org.apache.logging.log4j.ThreadContext;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.apache.logging.log4j.message.SimpleMessage;
+import org.apache.logging.log4j.spi.DefaultThreadContextStack;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class TTCCLayoutTest {
+
+    @Test
+    public void test0() {
+        DefaultThreadContextStack contextStack = new DefaultThreadContextStack(true);
+        contextStack.clear();
+        test(contextStack, "");
+    }
+
+    @Test
+    public void test1() {
+        DefaultThreadContextStack contextStack = new DefaultThreadContextStack(true);
+        contextStack.clear();
+        contextStack.push("foo");
+        test(contextStack, "foo ");
+    }
+
+    @Test
+    public void test2() {
+        DefaultThreadContextStack contextStack = new DefaultThreadContextStack(true);
+        contextStack.clear();
+        contextStack.push("foo");
+        contextStack.push("bar");
+        test(contextStack, "foo bar ");
+    }
+
+    private void test(ThreadContext.ContextStack contextStack, String stackOutput) {
+        TTCCLayout layout = TTCCLayout.createLayout();
+
+        Log4jLogEvent event = Log4jLogEvent.newBuilder()
+                .setLoggerName("a.B")
+                .setLevel(org.apache.logging.log4j.Level.DEBUG)
+                .setMessage(new SimpleMessage("Msg"))
+                .setContextStack(contextStack)
+                .setTimeMillis(System.currentTimeMillis() + 17).build();
+
+        String result = layout.toSerializable(event);
+
+        String expected = String.valueOf(event.getTimeMillis() - layout.startTime) +
+                ' ' +
+                '[' +
+                event.getThreadName() +
+                "] " +
+                event.getLevel().toString() +
+                ' ' +
+                event.getLoggerName() +
+                ' ' +
+                stackOutput +
+                "- " +
+                event.getMessage() +
+                System.getProperty("line.separator");
+
+        assertEquals(expected, result);
+    }
+
+}


[10/11] logging-log4j2 git commit: Ported Log4j 1's XMLLayout

Posted by mi...@apache.org.
Ported Log4j 1's XMLLayout


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/8e01bde3
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/8e01bde3
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/8e01bde3

Branch: refs/heads/LOG4J2-1512
Commit: 8e01bde35dfc47e071168f8554864ce4e8258007
Parents: f511f84
Author: Mikael St�ldal <mi...@staldal.nu>
Authored: Sun Aug 14 21:37:26 2016 +0200
Committer: Mikael St�ldal <mi...@staldal.nu>
Committed: Sun Aug 14 21:37:26 2016 +0200

----------------------------------------------------------------------
 log4j-1.2-api/pom.xml                           |   4 +
 .../config/Log4j1ConfigurationFactory.java      |   4 +-
 .../apache/log4j/layout/Log4j1XmlLayout.java    | 104 +++++++++++++++++++
 .../config/Log4j1ConfigurationFactoryTest.java  |  11 +-
 .../log4j/layout/Log4j1XmlLayoutTest.java       |  48 +++++++++
 5 files changed, 163 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8e01bde3/log4j-1.2-api/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/pom.xml b/log4j-1.2-api/pom.xml
index 779f050..76b1937 100644
--- a/log4j-1.2-api/pom.xml
+++ b/log4j-1.2-api/pom.xml
@@ -54,6 +54,10 @@
       <artifactId>log4j-api</artifactId>
     </dependency>
     <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-lang3</artifactId>
+    </dependency>
+    <dependency>
       <groupId>org.apache.logging.log4j</groupId>
       <artifactId>log4j-api</artifactId>
       <type>test-jar</type>

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8e01bde3/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 d351897..d0126bf 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
@@ -57,6 +57,7 @@ import org.apache.logging.log4j.status.StatusLogger;
  * <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>
  * </ul>
  * </ul>
@@ -143,8 +144,7 @@ public class Log4j1ConfigurationFactory extends ConfigurationFactory {
                 break;
             }
             case "org.apache.log4j.xml.XMLLayout": {
-                // We cannot use the XmlLayout in Log4j 2 since it has a significantly different format
-                reportWarning("Log4j 1 XMLLayout is not supported");
+                appenderBuilder.add(builder.newLayout("Log4j1XmlLayout"));
                 break;
             }
             default:

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8e01bde3/log4j-1.2-api/src/main/java/org/apache/log4j/layout/Log4j1XmlLayout.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/layout/Log4j1XmlLayout.java b/log4j-1.2-api/src/main/java/org/apache/log4j/layout/Log4j1XmlLayout.java
new file mode 100644
index 0000000..d602b41
--- /dev/null
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/layout/Log4j1XmlLayout.java
@@ -0,0 +1,104 @@
+/*
+ * 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.layout;
+
+import org.apache.commons.lang3.StringUtils;
+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.PluginFactory;
+import org.apache.logging.log4j.core.layout.AbstractStringLayout;
+import org.apache.logging.log4j.core.layout.ByteBufferDestination;
+import org.apache.logging.log4j.core.util.Transform;
+
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+
+/**
+ * Port of XMLLayout in Log4j 1.x. Provided for compatibility with existing Log4j 1 configurations.
+ *
+ * Originally developed by Ceki G&uuml;lc&uuml;, Mathias Bogaert.
+ */
+@Plugin(name = "Log4j1XmlLayout", category = Node.CATEGORY, elementType = Layout.ELEMENT_TYPE, printObject = true)
+public final class Log4j1XmlLayout extends AbstractStringLayout {
+
+    @PluginFactory
+    public static Log4j1XmlLayout createLayout() {
+        return new Log4j1XmlLayout();
+    }
+
+    private Log4j1XmlLayout() {
+        super(StandardCharsets.UTF_8);
+    }
+
+    @Override
+    public void encode(final LogEvent event, final ByteBufferDestination destination) {
+        final StringBuilder text = getStringBuilder();
+        formatTo(event, text);
+        getStringBuilderEncoder().encode(text, destination);
+    }
+
+    @Override
+    public String toSerializable(final LogEvent event) {
+        final StringBuilder text = getStringBuilder();
+        formatTo(event, text);
+        return text.toString();
+    }
+
+    private void formatTo(final LogEvent event, final StringBuilder buf) {
+        // We yield to the \r\n heresy.
+
+        buf.append("<log4j:event logger=\"");
+        buf.append(Transform.escapeHtmlTags(event.getLoggerName()));
+        buf.append("\" timestamp=\"");
+        buf.append(event.getTimeMillis());
+        buf.append("\" level=\"");
+        buf.append(Transform.escapeHtmlTags(String.valueOf(event.getLevel())));
+        buf.append("\" thread=\"");
+        buf.append(Transform.escapeHtmlTags(event.getThreadName()));
+        buf.append("\">\r\n");
+
+        buf.append("<log4j:message><![CDATA[");
+        // Append the rendered message. Also make sure to escape any existing CDATA sections.
+        Transform.appendEscapingCData(buf, event.getMessage().getFormattedMessage());
+        buf.append("]]></log4j:message>\r\n");
+
+        List<String> ndc = event.getContextStack().asList();
+        if (!ndc.isEmpty()) {
+            buf.append("<log4j:NDC><![CDATA[");
+            Transform.appendEscapingCData(buf, StringUtils.join(ndc, ' '));
+            buf.append("]]></log4j:NDC>\r\n");
+        }
+
+        @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
+        Throwable thrown = event.getThrown();
+        if (thrown != null) {
+            buf.append("<log4j:throwable><![CDATA[");
+            buf.append(thrown.toString());
+            buf.append("\r\n");
+            for (StackTraceElement element : thrown.getStackTrace()) {
+                Transform.appendEscapingCData(buf, "\tat " + element.toString());
+                buf.append("\r\n");
+            }
+            buf.append("]]></log4j:throwable>\r\n");
+        }
+
+        buf.append("</log4j:event>\r\n\r\n");
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8e01bde3/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 48a154d..35445c4 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
@@ -16,8 +16,7 @@
  */
 package org.apache.log4j.config;
 
-import java.net.URL;
-
+import org.apache.log4j.layout.Log4j1XmlLayout;
 import org.apache.log4j.layout.TTCCLayout;
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.core.Layout;
@@ -27,11 +26,11 @@ import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.LoggerConfig;
 import org.apache.logging.log4j.core.layout.HtmlLayout;
 import org.apache.logging.log4j.core.layout.PatternLayout;
-import org.apache.logging.log4j.core.layout.XmlLayout;
 import org.junit.Assert;
-import org.junit.Ignore;
 import org.junit.Test;
 
+import java.net.URL;
+
 public class Log4j1ConfigurationFactoryTest {
 
     private Layout<?> testConsole(final String configResource) throws Exception {
@@ -82,9 +81,9 @@ public class Log4j1ConfigurationFactoryTest {
         Assert.assertTrue(layout instanceof TTCCLayout);
     }
 
-    @Ignore("XmlLayout not supported")
+    @Test
     public void testConsoleXmlLayout() throws Exception {
         final Layout<?> layout = testConsole("config-1.2/log4j-console-XmlLayout.properties");
-        Assert.assertTrue(layout instanceof XmlLayout);
+        Assert.assertTrue(layout instanceof Log4j1XmlLayout);
     }
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8e01bde3/log4j-1.2-api/src/test/java/org/apache/log4j/layout/Log4j1XmlLayoutTest.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/layout/Log4j1XmlLayoutTest.java b/log4j-1.2-api/src/test/java/org/apache/log4j/layout/Log4j1XmlLayoutTest.java
new file mode 100644
index 0000000..9898550
--- /dev/null
+++ b/log4j-1.2-api/src/test/java/org/apache/log4j/layout/Log4j1XmlLayoutTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.layout;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.apache.logging.log4j.message.SimpleMessage;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class Log4j1XmlLayoutTest {
+
+    @Test
+    public void testWithoutThrown() {
+        Log4j1XmlLayout layout = Log4j1XmlLayout.createLayout();
+
+        Log4jLogEvent event = Log4jLogEvent.newBuilder()
+                .setLoggerName("a.B")
+                .setLevel(Level.INFO)
+                .setMessage(new SimpleMessage("Hello, World"))
+                .setTimeMillis(System.currentTimeMillis() + 17).build();
+
+        String result = layout.toSerializable(event);
+
+        String expected =
+                "<log4j:event logger=\"a.B\" timestamp=\"" + event.getTimeMillis() + "\" level=\"INFO\" thread=\"main\">\r\n" +
+                "<log4j:message><![CDATA[Hello, World]]></log4j:message>\r\n" +
+                "</log4j:event>\r\n\r\n";
+
+        assertEquals(expected, result);
+    }
+
+}