diff --git a/buildSrc/src/main/java/org/springframework/boot/build/docs/ApplicationRunner.java b/buildSrc/src/main/java/org/springframework/boot/build/docs/ApplicationRunner.java index eede77d599c..d84871efe99 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/docs/ApplicationRunner.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/docs/ApplicationRunner.java @@ -21,7 +21,6 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -134,10 +133,8 @@ public class ApplicationRunner extends DefaultTask { private void awaitLogging(Process process) { long end = System.currentTimeMillis() + 30000; String expectedLogging = this.expectedLogging.get(); - List outputLines = Collections.emptyList(); while (System.currentTimeMillis() < end) { - outputLines = outputLines(); - for (String line : outputLines) { + for (String line : outputLines()) { if (line.contains(expectedLogging)) { return; } @@ -146,10 +143,7 @@ public class ApplicationRunner extends DefaultTask { throw new IllegalStateException("Process exited before '" + expectedLogging + "' was logged"); } } - StringBuilder message = new StringBuilder( - "After 30 seconds '" + expectedLogging + "' had not be logged in the following output:\n\n"); - outputLines.forEach((line) -> message.append(line).append("\n")); - throw new IllegalStateException(message.toString()); + throw new IllegalStateException("'" + expectedLogging + "' was not logged within 30 seconds"); } private List outputLines() { @@ -177,8 +171,8 @@ public class ApplicationRunner extends DefaultTask { private List normalize(List lines) { List normalizedLines = lines; Map normalizations = new HashMap<>(this.normalizations); - normalizations.put("(Starting .* using Java .* on ).*( with PID [\\d]+ \\().*( started by ).*( in ).*(\\))", - "$1myhost$2" + this.applicationJar.get() + "$3myuser$4/opt/apps/$5"); + normalizations.put("(Starting .* using Java .* with PID [\\d]+ \\().*( started by ).*( in ).*(\\))", + "$1" + this.applicationJar.get() + "$2myuser$3/opt/apps/$4"); for (Entry normalization : normalizations.entrySet()) { Pattern pattern = Pattern.compile(normalization.getKey()); normalizedLines = normalize(normalizedLines, pattern, normalization.getValue()); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/resources/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/sample.log b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/resources/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/sample.log index db643177395..9b8f1ab7ece 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/resources/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/sample.log +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/resources/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/sample.log @@ -6,7 +6,7 @@ =========|_|==============|___/=/_/_/_/ :: Spring Boot :: -2017-08-08 17:12:30.910 INFO 19866 --- [ main] s.f.SampleWebFreeMarkerApplication : Starting SampleWebFreeMarkerApplication on host.local with PID 19866 +2017-08-08 17:12:30.910 INFO 19866 --- [ main] s.f.SampleWebFreeMarkerApplication : Starting SampleWebFreeMarkerApplication with PID 19866 2017-08-08 17:12:30.913 INFO 19866 --- [ main] s.f.SampleWebFreeMarkerApplication : No active profile set, falling back to default profiles: default 2017-08-08 17:12:30.952 INFO 19866 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@76b10754: startup date [Tue Aug 08 17:12:30 BST 2017]; root of context hierarchy 2017-08-08 17:12:31.878 INFO 19866 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/StartupInfoLogger.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/StartupInfoLogger.java index 06ffc52a0f3..1f3104bb60b 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/StartupInfoLogger.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/StartupInfoLogger.java @@ -17,12 +17,10 @@ package org.springframework.boot; import java.lang.management.ManagementFactory; -import java.net.InetAddress; import java.time.Duration; 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; @@ -42,10 +40,6 @@ import org.springframework.util.StringUtils; */ class StartupInfoLogger { - private static final Log logger = LogFactory.getLog(StartupInfoLogger.class); - - private static final long HOST_NAME_RESOLVE_THRESHOLD = 200; - private final Class sourceClass; StartupInfoLogger(Class sourceClass) { @@ -71,7 +65,6 @@ class StartupInfoLogger { appendApplicationName(message); appendVersion(message, this.sourceClass); appendJavaVersion(message); - appendOn(message); appendPid(message); appendContext(message); return message; @@ -116,26 +109,6 @@ class StartupInfoLogger { append(message, "v", () -> source.getPackage().getImplementationVersion()); } - private void appendOn(StringBuilder message) { - long startTime = System.currentTimeMillis(); - append(message, "on ", () -> InetAddress.getLocalHost().getHostName()); - long resolveTime = System.currentTimeMillis() - startTime; - if (resolveTime > HOST_NAME_RESOLVE_THRESHOLD) { - logger.warn(LogMessage.of(() -> { - StringBuilder warning = new StringBuilder(); - warning.append("InetAddress.getLocalHost().getHostName() took "); - warning.append(resolveTime); - warning.append(" milliseconds to respond."); - warning.append(" Please verify your network configuration"); - if (System.getProperty("os.name").toLowerCase().contains("mac")) { - warning.append(" (macOS machines may need to add entries to /etc/hosts)"); - } - warning.append("."); - return warning; - })); - } - } - private void appendPid(StringBuilder message) { append(message, "with PID ", ApplicationPid::new); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/StartupInfoLoggerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/StartupInfoLoggerTests.java index ee809d8a71f..e22f6cf9f05 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/StartupInfoLoggerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/StartupInfoLoggerTests.java @@ -16,8 +16,6 @@ package org.springframework.boot; -import java.net.InetAddress; -import java.net.UnknownHostException; import java.time.Duration; import org.apache.commons.logging.Log; @@ -43,29 +41,28 @@ class StartupInfoLoggerTests { private final Log log = mock(Log.class); @Test - void startingFormat() throws UnknownHostException { + void startingFormat() { given(this.log.isInfoEnabled()).willReturn(true); new StartupInfoLogger(getClass()).logStarting(this.log); ArgumentCaptor captor = ArgumentCaptor.forClass(Object.class); then(this.log).should().info(captor.capture()); assertThat(captor.getValue().toString()).contains("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") + ")"); + + System.getProperty("java.version") + " with PID " + new ApplicationPid() + " (started by " + + System.getProperty("user.name") + " in " + System.getProperty("user.dir") + ")"); } @Test - void startingFormatInAotMode() throws UnknownHostException { + void startingFormatInAotMode() { System.setProperty("spring.aot.enabled", "true"); try { given(this.log.isInfoEnabled()).willReturn(true); new StartupInfoLogger(getClass()).logStarting(this.log); ArgumentCaptor 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") + ")"); + assertThat(captor.getValue().toString()) + .contains("Starting AOT-processed " + getClass().getSimpleName() + " using Java " + + System.getProperty("java.version") + " with PID " + new ApplicationPid() + " (started by " + + System.getProperty("user.name") + " in " + System.getProperty("user.dir") + ")"); } finally {