From 9199fecae39a3edf5068c3a15998513582148fd6 Mon Sep 17 00:00:00 2001 From: Tyler Gregory Date: Fri, 21 Feb 2025 15:19:47 -0600 Subject: [PATCH] Ensure StandardStackTracePrinter respects stacktrace.root configuration property See gh-44398 Signed-off-by: Tyler Gregory --- .../StructuredLoggingJsonProperties.java | 2 +- .../StructuredLoggingJsonPropertiesTests.java | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/structured/StructuredLoggingJsonProperties.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/structured/StructuredLoggingJsonProperties.java index ef6ebbf2e8e3..3ec3131ec369 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/structured/StructuredLoggingJsonProperties.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/structured/StructuredLoggingJsonProperties.java @@ -120,7 +120,7 @@ private boolean hasAnyOtherProperty() { } 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); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/structured/StructuredLoggingJsonPropertiesTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/structured/StructuredLoggingJsonPropertiesTests.java index 8d19c71569a8..e1b2cafcfa1f 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/structured/StructuredLoggingJsonPropertiesTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/structured/StructuredLoggingJsonPropertiesTests.java @@ -152,12 +152,11 @@ void createPrinterWhenStandardAppliesCustomizations() { .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 @@ void createPrinterWhenClassNameInjectsConfiguredPrinter() { 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