Skip to content

Commit

Permalink
rename to "withOriginalStackTrace"
Browse files Browse the repository at this point in the history
Signed-off-by: Gregor Zeitlinger <[email protected]>
  • Loading branch information
zeitlinger committed Apr 22, 2024
1 parent 61b7a83 commit 1d4eb4a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public class JsonEncoder extends EncoderBase<ILoggingEvent> {
private boolean withMessage = true;
private boolean withArguments = true;
private boolean withThrowable = true;
private boolean withRawThrowable = false;
private boolean withOriginalStackTrace = false;
private boolean withFormattedMessage = false;


Expand Down Expand Up @@ -194,7 +194,7 @@ public byte[] encode(ILoggingEvent event) {
if (withArguments)
appendArgumentArray(sb, event);

if (withThrowable || withRawThrowable)
if (withThrowable)
appendThrowableProxy(sb, THROWABLE_ATTR_NAME, event.getThrowableProxy());

sb.append(CLOSE_OBJ);
Expand Down Expand Up @@ -268,8 +268,8 @@ private void appendThrowableProxy(StringBuilder sb, String attributeName, IThrow
}

sb.append(VALUE_SEPARATOR);
if (withRawThrowable) {
appenderMember(sb, "stackTrace", getRawThrowable(itp));
if (withOriginalStackTrace) {
appenderMember(sb, "stackTrace", getOriginalStackTrace(itp));
} else {
appendSTEPArray(sb, itp.getStackTraceElementProxyArray(), itp.getCommonFrames());
}
Expand All @@ -279,7 +279,7 @@ private void appendThrowableProxy(StringBuilder sb, String attributeName, IThrow
appenderMemberWithIntValue(sb, COMMON_FRAMES_COUNT_ATTR_NAME, itp.getCommonFrames());
}

if (!withRawThrowable) {
if (!withOriginalStackTrace) {
IThrowableProxy cause = itp.getCause();
if (cause != null) {
sb.append(VALUE_SEPARATOR);
Expand Down Expand Up @@ -308,13 +308,13 @@ private void appendThrowableProxy(StringBuilder sb, String attributeName, IThrow

}

private static String getRawThrowable(IThrowableProxy throwableProxy) {
private static String getOriginalStackTrace(IThrowableProxy throwableProxy) {
StringBuilder sb = new StringBuilder();
getRawThrowable(throwableProxy, sb, 0);
getOriginalStackTrace(throwableProxy, sb, 0);
return sb.toString();
}

private static void getRawThrowable(IThrowableProxy throwable, StringBuilder sb, int depth) {
private static void getOriginalStackTrace(IThrowableProxy throwable, StringBuilder sb, int depth) {
if (throwable == null) {
return;
}
Expand All @@ -325,7 +325,7 @@ private static void getRawThrowable(IThrowableProxy throwable, StringBuilder sb,
for (StackTraceElementProxy step : throwable.getStackTraceElementProxyArray()) {
sb.append(TAB).append(step).append(NEWLINE);
}
getRawThrowable(throwable.getCause(), sb, depth + 1);
getOriginalStackTrace(throwable.getCause(), sb, depth + 1);
}

private void appendSTEPArray(StringBuilder sb, StackTraceElementProxy[] stepArray, int commonFrames) {
Expand Down Expand Up @@ -543,11 +543,11 @@ public void setWithThrowable(boolean withThrowable) {
}

/**
* @param withRawThrowable
* @param withOriginalStackTrace
* @since 1.5.7
*/
public void setWithRawThrowable(boolean withRawThrowable) {
this.withRawThrowable = withRawThrowable;
public void setWithOriginalStackTrace(boolean withOriginalStackTrace) {
this.withOriginalStackTrace = withOriginalStackTrace;
}

public void setWithFormattedMessage(boolean withFormattedMessage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,11 @@ void withThrowable() throws JsonProcessingException {
}

@Test
void withRawThrowable() throws IOException {
void withOriginalStackTrace() throws IOException {
Throwable t = new RuntimeException("test", new IllegalStateException("test cause"));
LoggingEvent event = new LoggingEvent("in withThrowable test", logger, Level.WARN, "hello kvp", t, null);

jsonEncoder.setWithRawThrowable(true);
jsonEncoder.setWithOriginalStackTrace(true);
byte[] resultBytes = jsonEncoder.encode(event);
String resultString = new String(resultBytes, StandardCharsets.UTF_8).trim();

Expand Down

0 comments on commit 1d4eb4a

Please sign in to comment.