logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1405299 - in /logging/log4j/log4j2/trunk: core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java core/src/test/java/org/apache/logging/log4j/core/pattern/PatternParserTest.java src/changes/changes.xml
Date Sat, 03 Nov 2012 07:21:41 GMT
Author: rgoers
Date: Sat Nov  3 07:21:40 2012
New Revision: 1405299

URL: http://svn.apache.org/viewvc?rev=1405299&view=rev
Log:
LOG4J2-107 PatternParser was not properly handling adjacent nested options

Modified:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/pattern/PatternParserTest.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java?rev=1405299&r1=1405298&r2=1405299&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java
Sat Nov  3 07:21:40 2012
@@ -210,13 +210,13 @@ public final class PatternParser {
      */
     private static int extractOptions(String pattern, int i, List<String> options)
{
         while ((i < pattern.length()) && (pattern.charAt(i) == '{')) {
-            int begin = i;
+            int begin = i++;
             int end;
             int depth = 0;
             do {
                 end = pattern.indexOf('}', i);
                 if (end != -1) {
-                    int next = pattern.indexOf("{", i + 1);
+                    int next = pattern.indexOf("{", i);
                     if (next != -1 && next < end) {
                         i = end + 1;
                         ++depth;

Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/pattern/PatternParserTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/pattern/PatternParserTest.java?rev=1405299&r1=1405298&r2=1405299&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/pattern/PatternParserTest.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/pattern/PatternParserTest.java
Sat Nov  3 07:21:40 2012
@@ -55,6 +55,8 @@ public class PatternParserTest {
     private String mdcMsgPattern5 = "%m : %X{key1},%X{key2},%X{key3}%n";
 
     private static String customPattern = "[%d{yyyyMMdd HH:mm:ss,SSS}] %-5p [%-25.25c{1}:%-4L]
- %m%n";
+    private static String nestedPattern =
+        "%highlight{%d{dd MMM yyyy HH:mm:ss,SSS}{GMT+0} [%t] %-5level: %msg%n%throwable}";
 
     private static final String LINE_SEP = System.getProperty("line.separator");
 
@@ -103,9 +105,26 @@ public class PatternParserTest {
             formatter.format(event, buf);
         }
         String str = buf.toString();
-        String expected = "INFO  [PatternParserTest        :96  ] - Hello, world" + LINE_SEP;
+        String expected = "INFO  [PatternParserTest        :98  ] - Hello, world" + LINE_SEP;
         assertTrue("Expected to end with: " + expected + ". Actual: " + str, str.endsWith(expected));
     }
 
+    @Test
+    public void testNestedPattern() {
+        List<PatternFormatter> formatters = parser.parse(nestedPattern);
+        assertNotNull(formatters);
+        Throwable t = new Throwable();
+        StackTraceElement[] elements = t.getStackTrace();
+        LogEvent event = new Log4jLogEvent("org.apache.logging.log4j.PatternParserTest",
MarkerManager.getMarker("TEST"),
+            Logger.class.getName(), Level.INFO, new SimpleMessage("Hello, world"), null,
+            null, null, "Thread1", elements[0], System.currentTimeMillis());
+        StringBuilder buf = new StringBuilder();
+        for (PatternFormatter formatter : formatters) {
+            formatter.format(event, buf);
+        }
+        String str = buf.toString();
+        String expected = "] INFO : Hello, world\n\u001B[m";
+        assertTrue(" Expected to end with: " + expected + ". Actual: " + str, str.endsWith(expected));
+    }
 
 }

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1405299&r1=1405298&r2=1405299&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Sat Nov  3 07:21:40 2012
@@ -23,6 +23,9 @@
 
   <body>
     <release version="2.0-beta3" date="TBD" description= "Bug fixes and enhancements">
+      <action issue="LOG4J2-107" dev="rgoers" type="fix">
+        PatternParser was not properly handling adjacent nested options
+      </action>
       <action issue="LOG4J2-95" dev="rgoers" type="fix">
         Add support for loading plugins inside the OSGi bundle.
       </action>



Mime
View raw message