Skip to content

Commit db248b8

Browse files
committed
Add info log message if AOT mode is enabled
Closes gh-32396
1 parent 99765e7 commit db248b8

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/StartupInfoLogger.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.commons.logging.Log;
2525
import org.apache.commons.logging.LogFactory;
2626

27+
import org.springframework.aot.AotDetector;
2728
import org.springframework.boot.system.ApplicationHome;
2829
import org.springframework.boot.system.ApplicationPid;
2930
import org.springframework.context.ApplicationContext;
@@ -64,7 +65,8 @@ void logStarted(Log applicationLog, Duration timeTakenToStartup) {
6465

6566
private CharSequence getStartingMessage() {
6667
StringBuilder message = new StringBuilder();
67-
message.append("Starting ");
68+
message.append("Starting");
69+
appendAotMode(message);
6870
appendApplicationName(message);
6971
appendVersion(message, this.sourceClass);
7072
appendJavaVersion(message);
@@ -85,7 +87,7 @@ private CharSequence getRunningMessage() {
8587

8688
private CharSequence getStartedMessage(Duration timeTakenToStartup) {
8789
StringBuilder message = new StringBuilder();
88-
message.append("Started ");
90+
message.append("Started");
8991
appendApplicationName(message);
9092
message.append(" in ");
9193
message.append(timeTakenToStartup.toMillis() / 1000.0);
@@ -100,9 +102,13 @@ private CharSequence getStartedMessage(Duration timeTakenToStartup) {
100102
return message;
101103
}
102104

105+
private void appendAotMode(StringBuilder message) {
106+
append(message, "", () -> AotDetector.useGeneratedArtifacts() ? "AOT-processed" : null);
107+
}
108+
103109
private void appendApplicationName(StringBuilder message) {
104-
String name = (this.sourceClass != null) ? ClassUtils.getShortName(this.sourceClass) : "application";
105-
message.append(name);
110+
append(message, "",
111+
() -> (this.sourceClass != null) ? ClassUtils.getShortName(this.sourceClass) : "application");
106112
}
107113

108114
private void appendVersion(StringBuilder message, Class<?> source) {

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/StartupInfoLoggerTests.java

+20
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
*
3737
* @author Dave Syer
3838
* @author Andy Wilkinson
39+
* @author Moritz Halbritter
3940
*/
4041
class StartupInfoLoggerTests {
4142

@@ -53,6 +54,25 @@ void startingFormat() throws UnknownHostException {
5354
+ System.getProperty("user.dir") + ")");
5455
}
5556

57+
@Test
58+
void startingFormatInAotMode() throws UnknownHostException {
59+
System.setProperty("spring.aot.enabled", "true");
60+
try {
61+
given(this.log.isInfoEnabled()).willReturn(true);
62+
new StartupInfoLogger(getClass()).logStarting(this.log);
63+
ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(Object.class);
64+
then(this.log).should().info(captor.capture());
65+
assertThat(captor.getValue().toString()).contains("Starting AOT-processed " + getClass().getSimpleName()
66+
+ " using Java " + System.getProperty("java.version") + " on "
67+
+ InetAddress.getLocalHost().getHostName() + " with PID " + new ApplicationPid() + " (started by "
68+
+ System.getProperty("user.name") + " in " + System.getProperty("user.dir") + ")");
69+
70+
}
71+
finally {
72+
System.clearProperty("spring.aot.enabled");
73+
}
74+
}
75+
5676
@Test
5777
void startedFormat() {
5878
given(this.log.isInfoEnabled()).willReturn(true);

0 commit comments

Comments
 (0)