Merge pull request #44398 from typat

* pr/44398:
  Ensure StandardStackTracePrinter respects stacktrace.root configuration property

Closes gh-44398
This commit is contained in:
Moritz Halbritter
2025-02-25 14:38:33 +01:00
2 changed files with 7 additions and 9 deletions

View File

@@ -120,7 +120,7 @@ record StructuredLoggingJsonProperties(Set<String> include, Set<String> exclude,
}
private StandardStackTracePrinter createStandardPrinter() {
StandardStackTracePrinter printer = (root() != Root.FIRST) ? StandardStackTracePrinter.rootFirst()
StandardStackTracePrinter printer = (root() == Root.FIRST) ? StandardStackTracePrinter.rootFirst()
: StandardStackTracePrinter.rootLast();
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
printer = map.from(this::maxLength).to(printer, StandardStackTracePrinter::withMaximumLength);

View File

@@ -152,12 +152,11 @@ class StructuredLoggingJsonPropertiesTests {
.withLineSeparator("\n");
String actual = TestException.withoutLineNumbers(printer.printStackTraceToString(exception));
assertThat(actual).isEqualToNormalizingNewlines("""
java.lang.RuntimeException: exception
at org.springframework.boot.logging.TestException.actualCreateException(TestException.java:NN)
at org.springframework.boot.logging.TestException.createException(TestException.java:NN)
... 2 filtered
Suppressed: java.lang.RuntimeException: supressed
at o...""");
java.lang.RuntimeException: root
at org.springframework.boot.logging.TestException.createTestException(TestException.java:NN)
at org.springframework.boot.logging.TestException$CreatorThread.run(TestException.java:NN)
Wrapped by: java.lang.RuntimeException: cause
at org.springframework.boot.log...""");
}
@Test
@@ -184,8 +183,7 @@ class StructuredLoggingJsonPropertiesTests {
true, null);
StackTracePrinter printer = properties.createPrinter();
String actual = TestException.withoutLineNumbers(printer.printStackTraceToString(exception));
assertThat(actual).isEqualTo("RuntimeExceptionexception! at org.spr...");
assertThat(actual).isEqualTo("RuntimeExceptionroot! at org.springfr...");
}
@Test