Skip to content

Commit

Permalink
Merge pull request #205 from jamezp/LOGMGR-210
Browse files Browse the repository at this point in the history
[LOGMGR-210] Use the StackTraceFormatter to format exceptions in structured formatters.
  • Loading branch information
jamezp authored Nov 6, 2018
2 parents 35f4cd3 + 947376b commit 820c1bd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package org.jboss.logmanager.formatters;

import java.io.PrintWriter;
import java.io.Writer;
import java.time.Instant;
import java.time.ZoneId;
Expand Down Expand Up @@ -248,9 +247,9 @@ public final synchronized String format(final ExtLogRecord record) {
}

if (isFormattedExceptionOutputType()) {
final StringBuilderWriter w = new StringBuilderWriter();
thrown.printStackTrace(new PrintWriter(w));
generator.add(getKey(Key.STACK_TRACE), w.toString());
final StringBuilder sb = new StringBuilder();
StackTraceFormatter.renderStackTrace(sb, thrown, false, -1);
generator.add(getKey(Key.STACK_TRACE), sb.toString());
}
}
if (details) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@
import java.io.StringWriter;

import org.junit.Assert;
import org.junit.Assume;
import org.junit.Test;

/**
* @author <a href="mailto:[email protected]">James R. Perkins</a>
*/
public class StackTraceFormatterTests {

private static final boolean IS_IBM_JDK = System.getProperty("java.vendor").startsWith("IBM");

@Test
public void compareSimpleStackTrace() {
final RuntimeException e = new RuntimeException();
Expand Down Expand Up @@ -57,6 +60,7 @@ public void compareCauseStackTrace() {

@Test
public void compareSuppressedAndCauseStackTrace() {
Assume.assumeFalse("The IBM JDK does not show print circular references.", IS_IBM_JDK);
final RuntimeException r1 = new RuntimeException("Exception 1");
final RuntimeException r2 = new RuntimeException("Exception 2", r1);
final RuntimeException r3 = new RuntimeException("Exception 3", r2);
Expand All @@ -76,6 +80,7 @@ public void compareSuppressedAndCauseStackTrace() {

@Test
public void compareNestedSuppressedStackTrace() {
Assume.assumeFalse("The IBM JDK does not show print circular references.", IS_IBM_JDK);
final RuntimeException r1 = new RuntimeException("Exception 1");
final RuntimeException r2 = new RuntimeException("Exception 2", r1);
final RuntimeException r3 = new RuntimeException("Exception 3", r2);
Expand All @@ -99,6 +104,7 @@ public void compareNestedSuppressedStackTrace() {

@Test
public void compareMultiNestedSuppressedStackTrace() {
Assume.assumeFalse("The IBM JDK does not show print circular references.", IS_IBM_JDK);
final Throwable cause = createMultiNestedCause();

final StringWriter writer = new StringWriter();
Expand All @@ -112,6 +118,7 @@ public void compareMultiNestedSuppressedStackTrace() {

@Test
public void compareMultiNestedSuppressedAndNestedCauseStackTrace() {
Assume.assumeFalse("The IBM JDK does not show print circular references.", IS_IBM_JDK);
final Throwable rootCause = createMultiNestedCause();
final RuntimeException cause = new RuntimeException("This is the parent", rootCause);

Expand Down

0 comments on commit 820c1bd

Please sign in to comment.