Add info log message if AOT mode is enabled
Closes gh-32396
This commit is contained in:
parent
99765e785f
commit
db248b80bb
|
@ -24,6 +24,7 @@ import java.util.concurrent.Callable;
|
|||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.aot.AotDetector;
|
||||
import org.springframework.boot.system.ApplicationHome;
|
||||
import org.springframework.boot.system.ApplicationPid;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
@ -64,7 +65,8 @@ class StartupInfoLogger {
|
|||
|
||||
private CharSequence getStartingMessage() {
|
||||
StringBuilder message = new StringBuilder();
|
||||
message.append("Starting ");
|
||||
message.append("Starting");
|
||||
appendAotMode(message);
|
||||
appendApplicationName(message);
|
||||
appendVersion(message, this.sourceClass);
|
||||
appendJavaVersion(message);
|
||||
|
@ -85,7 +87,7 @@ class StartupInfoLogger {
|
|||
|
||||
private CharSequence getStartedMessage(Duration timeTakenToStartup) {
|
||||
StringBuilder message = new StringBuilder();
|
||||
message.append("Started ");
|
||||
message.append("Started");
|
||||
appendApplicationName(message);
|
||||
message.append(" in ");
|
||||
message.append(timeTakenToStartup.toMillis() / 1000.0);
|
||||
|
@ -100,9 +102,13 @@ class StartupInfoLogger {
|
|||
return message;
|
||||
}
|
||||
|
||||
private void appendAotMode(StringBuilder message) {
|
||||
append(message, "", () -> AotDetector.useGeneratedArtifacts() ? "AOT-processed" : null);
|
||||
}
|
||||
|
||||
private void appendApplicationName(StringBuilder message) {
|
||||
String name = (this.sourceClass != null) ? ClassUtils.getShortName(this.sourceClass) : "application";
|
||||
message.append(name);
|
||||
append(message, "",
|
||||
() -> (this.sourceClass != null) ? ClassUtils.getShortName(this.sourceClass) : "application");
|
||||
}
|
||||
|
||||
private void appendVersion(StringBuilder message, Class<?> source) {
|
||||
|
|
|
@ -36,6 +36,7 @@ import static org.mockito.Mockito.mock;
|
|||
*
|
||||
* @author Dave Syer
|
||||
* @author Andy Wilkinson
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class StartupInfoLoggerTests {
|
||||
|
||||
|
@ -53,6 +54,25 @@ class StartupInfoLoggerTests {
|
|||
+ System.getProperty("user.dir") + ")");
|
||||
}
|
||||
|
||||
@Test
|
||||
void startingFormatInAotMode() throws UnknownHostException {
|
||||
System.setProperty("spring.aot.enabled", "true");
|
||||
try {
|
||||
given(this.log.isInfoEnabled()).willReturn(true);
|
||||
new StartupInfoLogger(getClass()).logStarting(this.log);
|
||||
ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(Object.class);
|
||||
then(this.log).should().info(captor.capture());
|
||||
assertThat(captor.getValue().toString()).contains("Starting AOT-processed " + getClass().getSimpleName()
|
||||
+ " using Java " + System.getProperty("java.version") + " on "
|
||||
+ InetAddress.getLocalHost().getHostName() + " with PID " + new ApplicationPid() + " (started by "
|
||||
+ System.getProperty("user.name") + " in " + System.getProperty("user.dir") + ")");
|
||||
|
||||
}
|
||||
finally {
|
||||
System.clearProperty("spring.aot.enabled");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void startedFormat() {
|
||||
given(this.log.isInfoEnabled()).willReturn(true);
|
||||
|
|
Loading…
Reference in New Issue