Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LOGMGR-210] Use the StackTraceFormatter to format exceptions in structured formatters. #205

Merged
merged 2 commits into from
Nov 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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