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 25970b4016b..0a3dc751056 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,9 +125,7 @@ public class DataSourcePoolMetricsAutoConfiguration { hikari.setMetricsTrackerFactory(new MicrometerMetricsTrackerFactory(this.registry)); } catch (Exception ex) { - if (logger.isWarnEnabled()) { - 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 c0719d7e5f9..ae1f38f38bc 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,10 +63,8 @@ public class DiskSpaceHealthIndicator extends AbstractHealthIndicator { builder.up(); } else { - if (logger.isWarnEnabled()) { - logger.warn(String.format("Free disk space below threshold. Available: %d bytes (threshold: %s)", - diskFreeInBytes, this.threshold)); - } + logger.warn(LogMessage.format("Free disk space below threshold. Available: %d bytes (threshold: %s)", + diskFreeInBytes, this.threshold)); builder.down(); } builder.withDetail("total", this.path.getTotalSpace()).withDetail("free", diskFreeInBytes) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java index 1d3ad3b3efa..585efa56825 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java @@ -111,7 +111,7 @@ public class Neo4jDataAutoConfiguration { @Bean OpenSessionInViewInterceptor neo4jOpenSessionInViewInterceptor(Neo4jProperties properties) { - if (properties.getOpenInView() == null && logger.isWarnEnabled()) { + if (properties.getOpenInView() == null) { logger.warn("spring.data.neo4j.open-in-view is enabled by default." + "Therefore, database queries may be performed during view " + "rendering. Explicitly configure " 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 79fedf6644c..8385bfc99d9 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; @@ -83,10 +84,11 @@ public class GroovyTemplateAutoConfiguration { public void checkTemplateLocationExists() { if (this.properties.isCheckTemplateLocation() && !isUsingGroovyAllJar()) { TemplateLocation location = new TemplateLocation(this.properties.getResourceLoaderPath()); - if (!location.exists(this.applicationContext) && logger.isWarnEnabled()) { - logger.warn("Cannot find template location: " + location - + " (please add some templates, check your Groovy " - + "configuration, or set spring.groovy.template.check-template-location=false)"); + if (!location.exists(this.applicationContext)) { + 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/jackson/JacksonAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java index adcb7baa113..79caab4a3eb 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java @@ -119,10 +119,8 @@ public class JacksonAutoConfiguration { @Bean SimpleModule jodaDateTimeSerializationModule(JacksonProperties jacksonProperties) { - if (logger.isWarnEnabled()) { - logger.warn("Auto-configuration of Jackson's Joda-Time integration is deprecated in favor of using " - + "java.time (JSR-310)."); - } + logger.warn("Auto-configuration of Jackson's Joda-Time integration is deprecated in favor of using " + + "java.time (JSR-310)."); SimpleModule module = new SimpleModule(); JacksonJodaDateFormat jacksonJodaFormat = getJacksonJodaDateFormat(jacksonProperties); if (jacksonJodaFormat != null) { 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 6b38496c86d..a6ad430c211 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,9 +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 e31ded7e15d..12d13cc640a 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,9 +55,7 @@ public class OptionalLiveReloadServer implements InitializingBean { if (!this.server.isStarted()) { this.server.start(); } - if (logger.isInfoEnabled()) { - 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 fd961f92a0a..344fa626abb 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,9 +127,7 @@ public class RemoteDevToolsAutoConfiguration { RemoteDevToolsProperties remote = properties.getRemote(); String servletContextPath = (servlet.getContextPath() != null) ? servlet.getContextPath() : ""; String url = servletContextPath + remote.getContextPath() + "/restart"; - if (logger.isWarnEnabled()) { - 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 71c64182a7f..39c09066260 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,12 +59,8 @@ public class ClassPathFolders implements Iterable { this.folders.add(ResourceUtils.getFile(url)); } catch (Exception ex) { - if (logger.isWarnEnabled()) { - logger.warn("Unable to get classpath URL " + url); - } - if (logger.isTraceEnabled()) { - 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 d29eb778cbb..837eaa7fea0 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,14 +81,14 @@ public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostPro public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { if (DevToolsEnablementDeducer.shouldEnable(Thread.currentThread()) && isLocalApplication(environment)) { if (canAddProperties(environment)) { - if (logger.isInfoEnabled()) { - 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.isInfoEnabled()) { - logger.info("For additional web related logging consider setting the '" + WEB_LOGGING - + "' property to 'DEBUG'"); + if (isWebApplication(environment) && !environment.containsProperty(WEB_LOGGING)) { + 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 26628facbc0..09663a67391 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,10 +115,8 @@ public class ClassPathChangeUploader implements ApplicationListener { throw new IllegalStateException("Class-Path attribute contains malformed URL", ex); } } - if (!nonExistentEntries.isEmpty() && logger.isInfoEnabled()) { - logger.info("The Class-Path manifest attribute in " + jarFile.getName() + if (!nonExistentEntries.isEmpty()) { + 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 5a5663e6820..87be6ec2d15 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,9 +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)"); - } - if (logger.isWarnEnabled()) { - 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/logging/LoggingApplicationListener.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/LoggingApplicationListener.java index af5e927c261..de5e762c4b8 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,9 +417,7 @@ public class LoggingApplicationListener implements GenericApplicationListener { system.setLogLevel(name, level); } catch (RuntimeException ex) { - if (this.logger.isErrorEnabled()) { - 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 e8988dd384f..86932077fa3 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,9 +77,7 @@ final class FailureAnalyzers implements SpringBootExceptionReporter { analyzers.add((FailureAnalyzer) constructor.newInstance()); } catch (Throwable ex) { - if (logger.isTraceEnabled()) { - 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 6974867e56f..efda4b1cff9 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,9 +92,7 @@ public class WebServerPortFileWriter implements ApplicationListener