Merge pull request #21559 from dreis2211

* gh-21559:
  Polish "Print the java version being used on startup"
  Print the java version being used on startup

Closes gh-21559
pull/21732/head
Andy Wilkinson 5 years ago
commit 2f06cbc9c9

@ -67,6 +67,7 @@ class StartupInfoLogger {
message.append("Starting ");
appendApplicationName(message);
appendVersion(message, this.sourceClass);
appendJavaVersion(message);
appendOn(message);
appendPid(message);
appendContext(message);
@ -147,6 +148,10 @@ class StartupInfoLogger {
}
}
private void appendJavaVersion(StringBuilder message) {
append(message, "using Java ", () -> System.getProperty("java.version"));
}
private void append(StringBuilder message, String prefix, Callable<Object> call) {
append(message, prefix, call, "");
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,10 +16,14 @@
package org.springframework.boot;
import java.net.InetAddress;
import java.net.UnknownHostException;
import org.apache.commons.logging.Log;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.springframework.boot.system.ApplicationPid;
import org.springframework.util.StopWatch;
import static org.assertj.core.api.Assertions.assertThat;
@ -38,12 +42,15 @@ class StartupInfoLoggerTests {
private final Log log = mock(Log.class);
@Test
void sourceClassIncluded() {
void startingFormat() throws UnknownHostException {
given(this.log.isInfoEnabled()).willReturn(true);
new StartupInfoLogger(getClass()).logStarting(this.log);
ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(Object.class);
verify(this.log).info(captor.capture());
assertThat(captor.getValue().toString()).startsWith("Starting " + getClass().getSimpleName());
assertThat(captor.getValue().toString()).matches("Starting " + 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") + "\\)");
}
@Test

Loading…
Cancel
Save