From ad3e5425d45499d09b65cfeaaec6f43bbb392d6e Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Tue, 11 Jul 2023 16:35:07 +0200 Subject: [PATCH] Reduce WARN level log output during test AOT processing Closes gh-30867 --- .../context/aot/TestContextAotGenerator.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/context/aot/TestContextAotGenerator.java b/spring-test/src/main/java/org/springframework/test/context/aot/TestContextAotGenerator.java index cfeb405ab150..20c686e562a4 100644 --- a/spring-test/src/main/java/org/springframework/test/context/aot/TestContextAotGenerator.java +++ b/spring-test/src/main/java/org/springframework/test/context/aot/TestContextAotGenerator.java @@ -46,7 +46,6 @@ import org.springframework.core.annotation.MergedAnnotation; import org.springframework.core.annotation.MergedAnnotations; import org.springframework.core.annotation.MergedAnnotations.SearchStrategy; -import org.springframework.core.log.LogMessage; import org.springframework.javapoet.ClassName; import org.springframework.test.context.BootstrapUtils; import org.springframework.test.context.ContextLoadException; @@ -195,8 +194,10 @@ private MultiValueMap> processAheadOfTime( ClassLoader classLoader = getClass().getClassLoader(); MultiValueMap> initializerClassMappings = new LinkedMultiValueMap<>(); mergedConfigMappings.forEach((mergedConfig, testClasses) -> { - logger.debug(LogMessage.format("Generating AOT artifacts for test classes %s", - testClasses.stream().map(Class::getName).toList())); + if (logger.isDebugEnabled()) { + logger.debug("Generating AOT artifacts for test classes " + + testClasses.stream().map(Class::getName).toList()); + } this.mergedConfigRuntimeHints.registerHints(this.runtimeHints, mergedConfig, classLoader); try { // Use first test class discovered for a given unique MergedContextConfiguration. @@ -209,8 +210,16 @@ private MultiValueMap> processAheadOfTime( generationContext.writeGeneratedContent(); } catch (Exception ex) { - logger.warn(LogMessage.format("Failed to generate AOT artifacts for test classes %s", - testClasses.stream().map(Class::getName).toList()), ex); + if (logger.isDebugEnabled()) { + logger.debug("Failed to generate AOT artifacts for test classes " + + testClasses.stream().map(Class::getName).toList(), ex); + } + else if (logger.isWarnEnabled()) { + logger.warn(""" + Failed to generate AOT artifacts for test classes %s. \ + Enable DEBUG logging to view the stack trace. %s""" + .formatted(testClasses.stream().map(Class::getName).toList(), ex)); + } } }); return initializerClassMappings;