Skip to content

Commit

Permalink
rename to "withPlainStackTrace"
Browse files Browse the repository at this point in the history
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
  • Loading branch information
zeitlinger committed Apr 23, 2024
1 parent 3c016c9 commit bfe33c6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public class JsonEncoder extends EncoderBase<ILoggingEvent> {
private static final String LINE_NUMBER_ATTR_NAME = "lineNumber";

public static final String STEP_ARRAY_NAME_ATTRIBUTE = "stepArray";
public static final String STACKTRACE_NAME_ATTRIBUTE = "stackTrace";

private static final char OPEN_OBJ = '{';
private static final char CLOSE_OBJ = '}';
Expand Down Expand Up @@ -122,7 +123,7 @@ public class JsonEncoder extends EncoderBase<ILoggingEvent> {
private boolean withMessage = true;
private boolean withArguments = true;
private boolean withThrowable = true;
private boolean withOriginalStackTrace = false;
private boolean withPlainStackTrace = false;
private boolean withFormattedMessage = false;


Expand Down Expand Up @@ -268,8 +269,8 @@ private void appendThrowableProxy(StringBuilder sb, String attributeName, IThrow
}

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

if (!withOriginalStackTrace) {
if (!withPlainStackTrace) {
IThrowableProxy cause = itp.getCause();
if (cause != null) {
sb.append(VALUE_SEPARATOR);
Expand Down Expand Up @@ -323,7 +324,7 @@ private static void getOriginalStackTrace(IThrowableProxy throwable, StringBuild
}
sb.append(throwable.getClassName()).append(": ").append(throwable.getMessage()).append(NEWLINE);
for (StackTraceElementProxy step : throwable.getStackTraceElementProxyArray()) {
sb.append(TAB).append(step).append(NEWLINE);
sb.append(TAB).append(step.getSTEAsString()).append(NEWLINE);
}
getOriginalStackTrace(throwable.getCause(), sb, depth + 1);
}
Expand Down Expand Up @@ -543,11 +544,11 @@ public void setWithThrowable(boolean withThrowable) {
}

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

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 withOriginalStackTrace() throws IOException {
void withPlainStackTrace() 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.setWithOriginalStackTrace(true);
jsonEncoder.setWithPlainStackTrace(true);
byte[] resultBytes = jsonEncoder.encode(event);
String resultString = new String(resultBytes, StandardCharsets.UTF_8).trim();

Expand Down

0 comments on commit bfe33c6

Please sign in to comment.