logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1177876 - in /logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src: main/java/org/apache/logging/log4j/core/impl/ main/java/org/apache/logging/log4j/core/pattern/ test/java/org/apache/logging/log4j/core/pattern/
Date Sat, 01 Oct 2011 00:30:25 GMT
Author: rgoers
Date: Sat Oct  1 00:30:24 2011
New Revision: 1177876

URL: http://svn.apache.org/viewvc?rev=1177876&view=rev
Log:
Add RootThrowablePatternConverter

Added:
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/RootThrowablePatternConverter.java
      - copied, changed from r1172052, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/ExtendedThrowablePatternConverter.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/pattern/RootThrowablePatternConverterTest.java
      - copied, changed from r1172052, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/pattern/ExtendedThrowablePatternConverterTest.java
Modified:
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java?rev=1177876&r1=1177875&r2=1177876&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java
Sat Oct  1 00:30:24 2011
@@ -138,6 +138,28 @@ public class ThrowableProxy extends Thro
         return throwable.getStackTrace();
     }
 
+    public String getRootCauseStackTrace() {
+        StringBuilder sb = new StringBuilder();
+        if (cause != null) {
+            formatWrapper(sb, cause);
+            sb.append("Wrapped by: ");
+        }
+        sb.append(throwable.toString());
+        sb.append("\n");
+        formatElements(sb, 0, throwable.getStackTrace(), callerPackageData);
+        return sb.toString();
+    }
+
+    public void formatWrapper(StringBuilder sb, ThrowableProxy cause) {
+        Throwable caused = cause.getCause();
+        if (caused != null) {
+            formatWrapper(sb, cause.cause);
+            sb.append("Wrapped by: ");
+        }
+        sb.append(cause).append("\n");
+        formatElements(sb, cause.commonElementCount, cause.getStackTrace(), cause.callerPackageData);
+    }
+
     public String getExtendedStackTrace() {
         StringBuilder sb = new StringBuilder(throwable.toString());
         sb.append("\n");

Copied: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/RootThrowablePatternConverter.java
(from r1172052, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/ExtendedThrowablePatternConverter.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/RootThrowablePatternConverter.java?p2=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/RootThrowablePatternConverter.java&p1=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/ExtendedThrowablePatternConverter.java&r1=1172052&r2=1177876&rev=1177876&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/ExtendedThrowablePatternConverter.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/RootThrowablePatternConverter.java
Sat Oct  1 00:30:24 2011
@@ -21,9 +21,6 @@ import org.apache.logging.log4j.core.Log
 import org.apache.logging.log4j.core.config.plugins.Plugin;
 import org.apache.logging.log4j.core.impl.ThrowableProxy;
 
-import java.io.PrintWriter;
-import java.io.StringWriter;
-
 
 /**
  * Outputs the Throwable portion of the LoggingEvent as a full stacktrace
@@ -33,16 +30,16 @@ import java.io.StringWriter;
  * The extended stack trace will also include the location of where the class was loaded
from and the
  * version of the jar if available.
  */
-@Plugin(name = "ExtendedThrowablePatternConverter", type = "Converter")
-@ConverterKeys({"xEx", "xThrowable", "xException"})
-public class ExtendedThrowablePatternConverter extends ThrowablePatternConverter {
+@Plugin(name = "RootThrowablePatternConverter", type = "Converter")
+@ConverterKeys({"rEx", "rThrowable", "rException"})
+public class RootThrowablePatternConverter extends ThrowablePatternConverter {
     /**
      * Private constructor.
      *
      * @param options options, may be null.
      */
-    private ExtendedThrowablePatternConverter(final String[] options) {
-        super("ExtendedThrowable", "throwable", options);
+    private RootThrowablePatternConverter(final String[] options) {
+        super("RootThrowable", "throwable", options);
     }
 
     /**
@@ -52,9 +49,9 @@ public class ExtendedThrowablePatternCon
      *                only the first line of the throwable will be formatted.
      * @return instance of class.
      */
-    public static ExtendedThrowablePatternConverter newInstance(
+    public static RootThrowablePatternConverter newInstance(
         final String[] options) {
-        return new ExtendedThrowablePatternConverter(options);
+        return new RootThrowablePatternConverter(options);
     }
 
     /**
@@ -68,7 +65,7 @@ public class ExtendedThrowablePatternCon
                 return;
             }
             ThrowableProxy t = (ThrowableProxy) throwable;
-            String trace = t.getExtendedStackTrace();
+            String trace = t.getRootCauseStackTrace();
             if (lines > 0) {
                 StringBuilder sb = new StringBuilder();
                 String[] array = trace.split("\n");

Copied: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/pattern/RootThrowablePatternConverterTest.java
(from r1172052, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/pattern/ExtendedThrowablePatternConverterTest.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/pattern/RootThrowablePatternConverterTest.java?p2=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/pattern/RootThrowablePatternConverterTest.java&p1=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/pattern/ExtendedThrowablePatternConverterTest.java&r1=1172052&r2=1177876&rev=1177876&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/pattern/ExtendedThrowablePatternConverterTest.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/pattern/RootThrowablePatternConverterTest.java
Sat Oct  1 00:30:24 2011
@@ -17,27 +17,20 @@
 package org.apache.logging.log4j.core.pattern;
 
 import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Marker;
 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.impl.Log4jLogEvent;
-import org.apache.logging.log4j.message.Message;
 import org.apache.logging.log4j.message.SimpleMessage;
 import org.junit.Before;
 import org.junit.Test;
 
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.List;
+import static org.junit.Assert.assertTrue;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
 
 /**
  *
  */
-public class ExtendedThrowablePatternConverterTest {
+public class RootThrowablePatternConverterTest {
 
 
 
@@ -48,19 +41,17 @@ public class ExtendedThrowablePatternCon
 
     @Test
     public void testFull() {
-        ExtendedThrowablePatternConverter converter = ExtendedThrowablePatternConverter.newInstance(null);
+        RootThrowablePatternConverter converter = RootThrowablePatternConverter.newInstance(null);
         Throwable cause = new NullPointerException("null pointer");
         Throwable parent = new IllegalArgumentException("IllegalArgument", cause);
         LogEvent event = new Log4jLogEvent("testLogger", null, this.getClass().getName(),
Level.DEBUG,
             new SimpleMessage("test exception"), parent);
         StringBuilder sb = new StringBuilder();
         converter.format(event, sb);
-        StringWriter sw = new StringWriter();
-        PrintWriter pw = new PrintWriter(sw);
-        parent.printStackTrace(pw);
         String result = sb.toString();
         //System.out.print(result);
-        result = result.replaceAll(" ~?\\[.*\\]", "");
-        assertEquals(sw.toString(), result);
+        assertTrue("Missing Exception",
+            result.contains("Wrapped by: java.lang.IllegalArgumentException: IllegalArgument"));
+        assertTrue("Incorrect start of msg", result.startsWith("java.lang.NullPointerException:
null pointer"));
     }
 }



Mime
View raw message