Skip to content

Commit ad3e542

Browse files
committed
Reduce WARN level log output during test AOT processing
Closes gh-30867
1 parent c418118 commit ad3e542

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

spring-test/src/main/java/org/springframework/test/context/aot/TestContextAotGenerator.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import org.springframework.core.annotation.MergedAnnotation;
4747
import org.springframework.core.annotation.MergedAnnotations;
4848
import org.springframework.core.annotation.MergedAnnotations.SearchStrategy;
49-
import org.springframework.core.log.LogMessage;
5049
import org.springframework.javapoet.ClassName;
5150
import org.springframework.test.context.BootstrapUtils;
5251
import org.springframework.test.context.ContextLoadException;
@@ -195,8 +194,10 @@ private MultiValueMap<ClassName, Class<?>> processAheadOfTime(
195194
ClassLoader classLoader = getClass().getClassLoader();
196195
MultiValueMap<ClassName, Class<?>> initializerClassMappings = new LinkedMultiValueMap<>();
197196
mergedConfigMappings.forEach((mergedConfig, testClasses) -> {
198-
logger.debug(LogMessage.format("Generating AOT artifacts for test classes %s",
199-
testClasses.stream().map(Class::getName).toList()));
197+
if (logger.isDebugEnabled()) {
198+
logger.debug("Generating AOT artifacts for test classes " +
199+
testClasses.stream().map(Class::getName).toList());
200+
}
200201
this.mergedConfigRuntimeHints.registerHints(this.runtimeHints, mergedConfig, classLoader);
201202
try {
202203
// Use first test class discovered for a given unique MergedContextConfiguration.
@@ -209,8 +210,16 @@ private MultiValueMap<ClassName, Class<?>> processAheadOfTime(
209210
generationContext.writeGeneratedContent();
210211
}
211212
catch (Exception ex) {
212-
logger.warn(LogMessage.format("Failed to generate AOT artifacts for test classes %s",
213-
testClasses.stream().map(Class::getName).toList()), ex);
213+
if (logger.isDebugEnabled()) {
214+
logger.debug("Failed to generate AOT artifacts for test classes " +
215+
testClasses.stream().map(Class::getName).toList(), ex);
216+
}
217+
else if (logger.isWarnEnabled()) {
218+
logger.warn("""
219+
Failed to generate AOT artifacts for test classes %s. \
220+
Enable DEBUG logging to view the stack trace. %s"""
221+
.formatted(testClasses.stream().map(Class::getName).toList(), ex));
222+
}
214223
}
215224
});
216225
return initializerClassMappings;

0 commit comments

Comments
 (0)