diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsAutoConfiguration.java index 2ee47d82ea..0a3dc75105 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsAutoConfiguration.java @@ -43,6 +43,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.jdbc.DataSourceUnwrapper; import org.springframework.boot.jdbc.metadata.DataSourcePoolMetadataProvider; import org.springframework.context.annotation.Configuration; +import org.springframework.core.log.LogMessage; import org.springframework.util.StringUtils; /** @@ -124,7 +125,7 @@ public class DataSourcePoolMetricsAutoConfiguration { hikari.setMetricsTrackerFactory(new MicrometerMetricsTrackerFactory(this.registry)); } catch (Exception ex) { - logger.warn("Failed to bind Hikari metrics: " + ex.getMessage()); + logger.warn(LogMessage.format("Failed to bind Hikari metrics: %s", ex.getMessage())); } } } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/system/DiskSpaceHealthIndicator.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/system/DiskSpaceHealthIndicator.java index 46f44f2b48..ae1f38f38b 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/system/DiskSpaceHealthIndicator.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/system/DiskSpaceHealthIndicator.java @@ -25,6 +25,7 @@ import org.springframework.boot.actuate.health.AbstractHealthIndicator; import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.HealthIndicator; import org.springframework.boot.actuate.health.Status; +import org.springframework.core.log.LogMessage; import org.springframework.util.unit.DataSize; /** @@ -62,7 +63,7 @@ public class DiskSpaceHealthIndicator extends AbstractHealthIndicator { builder.up(); } else { - logger.warn(String.format("Free disk space below threshold. Available: %d bytes (threshold: %s)", + logger.warn(LogMessage.format("Free disk space below threshold. Available: %d bytes (threshold: %s)", diskFreeInBytes, this.threshold)); builder.down(); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfiguration.java index 0bad6a8276..8385bfc99d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfiguration.java @@ -41,6 +41,7 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.core.log.LogMessage; import org.springframework.web.servlet.view.UrlBasedViewResolver; import org.springframework.web.servlet.view.groovy.GroovyMarkupConfig; import org.springframework.web.servlet.view.groovy.GroovyMarkupConfigurer; @@ -84,9 +85,10 @@ public class GroovyTemplateAutoConfiguration { if (this.properties.isCheckTemplateLocation() && !isUsingGroovyAllJar()) { TemplateLocation location = new TemplateLocation(this.properties.getResourceLoaderPath()); if (!location.exists(this.applicationContext)) { - logger.warn("Cannot find template location: " + location - + " (please add some templates, check your Groovy " - + "configuration, or set spring.groovy.template.check-template-location=false)"); + logger.warn(LogMessage.format( + "Cannot find template location: %s (please add some templates, check your Groovy " + + "configuration, or set spring.groovy.template.check-template-location=false)", + location)); } } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerInvoker.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerInvoker.java index d9891f0353..a6ad430c21 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerInvoker.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerInvoker.java @@ -25,6 +25,7 @@ import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.ObjectProvider; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationListener; +import org.springframework.core.log.LogMessage; /** * Bean to handle {@link DataSource} initialization by running {@literal schema-*.sql} on @@ -76,7 +77,8 @@ class DataSourceInitializerInvoker implements ApplicationListener String.format("%s 500 Server Error for %s", + request.exchange().getLogPrefix(), formatRequest(request))), throwable); } } diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/OptionalLiveReloadServer.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/OptionalLiveReloadServer.java index a6363fe767..12d13cc640 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/OptionalLiveReloadServer.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/OptionalLiveReloadServer.java @@ -21,6 +21,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.InitializingBean; import org.springframework.boot.devtools.livereload.LiveReloadServer; +import org.springframework.core.log.LogMessage; /** * Manages an optional {@link LiveReloadServer}. The {@link LiveReloadServer} may @@ -54,7 +55,7 @@ public class OptionalLiveReloadServer implements InitializingBean { if (!this.server.isStarted()) { this.server.start(); } - logger.info("LiveReload server is running on port " + this.server.getPort()); + logger.info(LogMessage.format("LiveReload server is running on port %s", this.server.getPort())); } catch (Exception ex) { logger.warn("Unable to start LiveReload server"); diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/RemoteDevToolsAutoConfiguration.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/RemoteDevToolsAutoConfiguration.java index 3d1111bec8..344fa626ab 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/RemoteDevToolsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/RemoteDevToolsAutoConfiguration.java @@ -48,6 +48,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; +import org.springframework.core.log.LogMessage; import org.springframework.http.server.ServerHttpRequest; /** @@ -126,7 +127,7 @@ public class RemoteDevToolsAutoConfiguration { RemoteDevToolsProperties remote = properties.getRemote(); String servletContextPath = (servlet.getContextPath() != null) ? servlet.getContextPath() : ""; String url = servletContextPath + remote.getContextPath() + "/restart"; - logger.warn("Listening for remote restart updates on " + url); + logger.warn(LogMessage.format("Listening for remote restart updates on %s", url)); Handler handler = new HttpRestartServerHandler(server); return new UrlHandlerMapper(url, handler); } diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/classpath/ClassPathFolders.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/classpath/ClassPathFolders.java index 0934568235..39c0906626 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/classpath/ClassPathFolders.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/classpath/ClassPathFolders.java @@ -26,6 +26,7 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.core.log.LogMessage; import org.springframework.util.ResourceUtils; /** @@ -58,8 +59,8 @@ public class ClassPathFolders implements Iterable { this.folders.add(ResourceUtils.getFile(url)); } catch (Exception ex) { - logger.warn("Unable to get classpath URL " + url); - logger.trace("Unable to get classpath URL " + url, ex); + logger.warn(LogMessage.format("Unable to get classpath URL %s", url)); + logger.trace(LogMessage.format("Unable to get classpath URL ", url), ex); } } } diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsPropertyDefaultsPostProcessor.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsPropertyDefaultsPostProcessor.java index 9d45de8f13..837eaa7fea 100755 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsPropertyDefaultsPostProcessor.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsPropertyDefaultsPostProcessor.java @@ -32,6 +32,7 @@ import org.springframework.core.annotation.Order; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.Environment; import org.springframework.core.env.MapPropertySource; +import org.springframework.core.log.LogMessage; import org.springframework.util.ClassUtils; /** @@ -80,12 +81,14 @@ public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostPro public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { if (DevToolsEnablementDeducer.shouldEnable(Thread.currentThread()) && isLocalApplication(environment)) { if (canAddProperties(environment)) { - logger.info("Devtools property defaults active! Set '" + ENABLED + "' to 'false' to disable"); + logger.info(LogMessage.format("Devtools property defaults active! Set '%s' to 'false' to disable", + ENABLED)); environment.getPropertySources().addLast(new MapPropertySource("devtools", PROPERTIES)); } if (isWebApplication(environment) && !environment.containsProperty(WEB_LOGGING)) { - logger.info("For additional web related logging consider setting the '" + WEB_LOGGING - + "' property to 'DEBUG'"); + logger.info(LogMessage.format( + "For additional web related logging consider setting the '%s' property to 'DEBUG'", + WEB_LOGGING)); } } } diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/remote/client/ClassPathChangeUploader.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/remote/client/ClassPathChangeUploader.java index fd2d8c27d5..09663a6739 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/remote/client/ClassPathChangeUploader.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/remote/client/ClassPathChangeUploader.java @@ -38,6 +38,7 @@ import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile; import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile.Kind; import org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles; import org.springframework.context.ApplicationListener; +import org.springframework.core.log.LogMessage; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; @@ -114,8 +115,8 @@ public class ClassPathChangeUploader implements ApplicationListener { } } if (!nonExistentEntries.isEmpty()) { - logger.info("The Class-Path manifest attribute in " + jarFile.getName() + logger.info(LogMessage.of(() -> "The Class-Path manifest attribute in " + jarFile.getName() + " referenced one or more files that do not exist: " - + StringUtils.collectionToCommaDelimitedString(nonExistentEntries)); + + StringUtils.collectionToCommaDelimitedString(nonExistentEntries))); } return urls; } diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/RestartApplicationListener.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/RestartApplicationListener.java index c4c4e15379..87be6ec2d1 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/RestartApplicationListener.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/RestartApplicationListener.java @@ -26,6 +26,7 @@ import org.springframework.boot.context.event.ApplicationStartingEvent; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationListener; import org.springframework.core.Ordered; +import org.springframework.core.log.LogMessage; /** * {@link ApplicationListener} to initialize the {@link Restarter}. @@ -73,7 +74,8 @@ public class RestartApplicationListener implements ApplicationListener InetAddress.getLocalHost().getHostName()); long resolveTime = System.currentTimeMillis() - startTime; - if (resolveTime > HOST_NAME_RESOLVE_THRESHOLD && logger.isWarnEnabled()) { - 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)"); - } - logger.warn(warning.append(".")); + 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; + })); } } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/FileEncodingApplicationListener.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/FileEncodingApplicationListener.java index 661c03c2a9..9cbb667aec 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/FileEncodingApplicationListener.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/FileEncodingApplicationListener.java @@ -64,12 +64,14 @@ public class FileEncodingApplicationListener String encoding = System.getProperty("file.encoding"); String desired = environment.getProperty("spring.mandatory-file-encoding"); if (encoding != null && !desired.equalsIgnoreCase(encoding)) { - logger.error("System property 'file.encoding' is currently '" + encoding + "'. It should be '" + desired - + "' (as defined in 'spring.mandatoryFileEncoding')."); - logger.error("Environment variable LANG is '" + System.getenv("LANG") - + "'. You could use a locale setting that matches encoding='" + desired + "'."); - logger.error("Environment variable LC_ALL is '" + System.getenv("LC_ALL") - + "'. You could use a locale setting that matches encoding='" + desired + "'."); + if (logger.isErrorEnabled()) { + logger.error("System property 'file.encoding' is currently '" + encoding + "'. It should be '" + desired + + "' (as defined in 'spring.mandatoryFileEncoding')."); + logger.error("Environment variable LANG is '" + System.getenv("LANG") + + "'. You could use a locale setting that matches encoding='" + desired + "'."); + logger.error("Environment variable LC_ALL is '" + System.getenv("LC_ALL") + + "'. You could use a locale setting that matches encoding='" + desired + "'."); + } throw new IllegalStateException("The Java Virtual Machine has not been configured to use the " + "desired default character encoding (" + desired + ")."); } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/LoggingApplicationListener.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/LoggingApplicationListener.java index 9ff891becc..de5e762c4b 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/LoggingApplicationListener.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/LoggingApplicationListener.java @@ -50,6 +50,7 @@ import org.springframework.core.Ordered; import org.springframework.core.ResolvableType; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.Environment; +import org.springframework.core.log.LogMessage; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.util.ResourceUtils; @@ -416,7 +417,7 @@ public class LoggingApplicationListener implements GenericApplicationListener { system.setLogLevel(name, level); } catch (RuntimeException ex) { - this.logger.error("Cannot set level '" + level + "' for '" + name + "'"); + this.logger.error(LogMessage.format("Cannot set level '%s' for '%s'", level, name)); } }; } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/FailureAnalyzers.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/FailureAnalyzers.java index cd15fc3c20..86932077fa 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/FailureAnalyzers.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/FailureAnalyzers.java @@ -77,7 +77,7 @@ final class FailureAnalyzers implements SpringBootExceptionReporter { analyzers.add((FailureAnalyzer) constructor.newInstance()); } catch (Throwable ex) { - logger.trace("Failed to load " + analyzerName, ex); + logger.trace(LogMessage.format("Failed to load %s", analyzerName), ex); } } AnnotationAwareOrderComparator.sort(analyzers); diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/context/WebServerPortFileWriter.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/context/WebServerPortFileWriter.java index 14b1c52971..efda4b1cff 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/context/WebServerPortFileWriter.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/context/WebServerPortFileWriter.java @@ -25,6 +25,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.boot.system.SystemProperties; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationListener; +import org.springframework.core.log.LogMessage; import org.springframework.util.Assert; import org.springframework.util.FileCopyUtils; import org.springframework.util.StringUtils; @@ -91,7 +92,7 @@ public class WebServerPortFileWriter implements ApplicationListener