Skip to content

Commit c565df9

Browse files
committed
Remove System.out calls in PreComputeFieldFeature
Closes gh-30571
1 parent 4b4a8af commit c565df9

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

spring-core/src/main/java/org/springframework/aot/nativex/feature/PreComputeFieldFeature.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,18 @@
2626
* GraalVM {@link Feature} that substitutes boolean field values that match a certain pattern
2727
* with values pre-computed AOT without causing class build-time initialization.
2828
*
29+
* <p>It is possible to pass <pre style="code">-Dspring.aot.precompute=verbose</pre> as a
30+
* <pre style="code">native-image</pre> compiler build argument to display detailed logs
31+
* about pre-computed fields.</p>
32+
*
2933
* @author Sebastien Deleuze
3034
* @author Phillip Webb
3135
* @since 6.0
3236
*/
3337
class PreComputeFieldFeature implements Feature {
3438

39+
private static final boolean verbose = "verbose".equals(System.getProperty("spring.aot.precompute"));
40+
3541
private static Pattern[] patterns = {
3642
Pattern.compile(Pattern.quote("org.springframework.core.NativeDetector#inNativeImage")),
3743
Pattern.compile(Pattern.quote("org.springframework.cglib.core.AbstractClassGenerator#inNativeImage")),
@@ -64,10 +70,14 @@ private void iterateFields(DuringAnalysisAccess access, Class<?> subtype) {
6470
try {
6571
Object fieldValue = provideFieldValue(field);
6672
access.registerFieldValueTransformer(field, (receiver, originalValue) -> fieldValue);
67-
System.out.println("Field " + fieldIdentifier + " set to " + fieldValue + " at build time");
73+
if (verbose) {
74+
System.out.println("Field " + fieldIdentifier + " set to " + fieldValue + " at build time");
75+
}
6876
}
6977
catch (Throwable ex) {
70-
System.out.println("Field " + fieldIdentifier + " will be evaluated at runtime due to this error during build time evaluation: " + ex.getMessage());
78+
if (verbose) {
79+
System.out.println("Field " + fieldIdentifier + " will be evaluated at runtime due to this error during build time evaluation: " + ex.getMessage());
80+
}
7181
}
7282
}
7383
}

0 commit comments

Comments
 (0)