Browse Source

Merge pull request #44398 from typat

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

Closes gh-44398
pull/44432/head
Moritz Halbritter 11 months ago
parent
commit
2ec99a7591
  1. 2
      spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/structured/StructuredLoggingJsonProperties.java
  2. 14
      spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/structured/StructuredLoggingJsonPropertiesTests.java

2
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/structured/StructuredLoggingJsonProperties.java

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

14
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/structured/StructuredLoggingJsonPropertiesTests.java

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

Loading…
Cancel
Save