From 21de3fba3cd5348c6c0d63f424dcd3ca650a92b7 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 9 Aug 2023 12:21:30 +0100 Subject: [PATCH] Describe quirks of JUL and Log4j2 in OutputCaptureExtension javadoc Closes gh-32562 --- .../test/system/OutputCaptureExtension.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/system/OutputCaptureExtension.java b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/system/OutputCaptureExtension.java index f3f9584832..a2159fe230 100644 --- a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/system/OutputCaptureExtension.java +++ b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/system/OutputCaptureExtension.java @@ -56,6 +56,30 @@ import org.junit.jupiter.api.extension.ParameterResolver; * } * * } + * + *

+ * To ensure that their output can be captured, Java Util Logging (JUL) and Log4j2 require + * additional configuration. + *

+ * To reliably capture output from Java Util Logging, reset its configuration after each + * test: + * + *

+ * @AfterEach
+ * void reset() throws Exception {
+ *     LogManager.getLogManager().readConfiguration();
+ * }
+ * 
+ *

+ * To reliably capture output from Log4j2, set the follow attribute of the + * console appender to true: + * + *

+ * <Appenders>
+ *     <Console name="Console" target="SYSTEM_OUT" follow="true">
+ *         ...
+ *     </Console>
+*  </Appenders>
  * 
* * @author Madhura Bhave