Convert Log4j 1 pattern so it works properly in Log4j 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/71f0762d Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/71f0762d Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/71f0762d Branch: refs/heads/LOG4J2-1010&LOG4J2-1447-injectable-contextdata&better-datastructure Commit: 71f0762d232d553afee91c99b46122b87e5e6be7 Parents: 03fe13f Author: Mikael Ståldal <mik...@staldal.nu> Authored: Sun Aug 21 11:16:20 2016 +0200 Committer: Mikael Ståldal <mik...@staldal.nu> Committed: Sun Aug 21 11:16:20 2016 +0200 ---------------------------------------------------------------------- .../config/Log4j1ConfigurationFactory.java | 20 +++++++++++--------- ...g4j-console-EnhancedPatternLayout.properties | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/71f0762d/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 74563a5..7fbb729 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 @@ -104,17 +104,19 @@ public class Log4j1ConfigurationFactory extends ConfigurationFactory { switch (layoutValue) { case "org.apache.log4j.PatternLayout": case "org.apache.log4j.EnhancedPatternLayout": { - final String pattern = getLog4jAppenderValue(properties, name, "layout.ConversionPattern", null); + final String pattern = getLog4jAppenderValue(properties, name, "layout.ConversionPattern", null) - // 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 (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 + .replace("%x", "%ndc") - // 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 + // 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 + .replace("%X", "%properties"); appenderBuilder.add(newPatternLayout(builder, pattern)); break; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/71f0762d/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 d8099f6..01a4463 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 %ndc: %m%n +log4j.appender.Console.layout.ConversionPattern=%d{ISO8601} [%t][%c] %-5p %X %x: %m%n log4j.logger.com.example.foo = DEBUG