From 731c19281788b8fba88df45d11eb8e83c94f7f1d Mon Sep 17 00:00:00 2001 From: dreis2211 Date: Mon, 25 May 2020 12:35:49 +0200 Subject: [PATCH 1/2] Print the java version being used on startup See gh-21559 --- .../java/org/springframework/boot/StartupInfoLogger.java | 5 +++++ 1 file changed, 5 insertions(+) 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 73dcf08b4b..9668fa77f1 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 @@ -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 call) { append(message, prefix, call, ""); } From 82cc7e972db37938d3b5088816a8236bd6ec67e2 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 5 Jun 2020 14:19:15 +0100 Subject: [PATCH 2/2] Polish "Print the java version being used on startup" See gh-21559 --- .../boot/StartupInfoLoggerTests.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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 668b61a3f3..7563cfd43e 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 @@ -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 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