From b81c0047f805fb920face59fad9e2b30fff021c8 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Mon, 3 Jan 2022 14:30:56 +0100 Subject: [PATCH] Polish "Log the reason that led Devtools to restart the app" See gh-28495 --- .../autoconfigure/LocalDevToolsAutoConfiguration.java | 11 ++++++++++- .../classpath/ClassPathFileChangeListener.java | 8 -------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java index 51a7a7809bd..56da3a997de 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 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. @@ -20,6 +20,9 @@ import java.io.File; import java.net.URL; import java.util.List; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -94,6 +97,8 @@ public class LocalDevToolsAutoConfiguration { @ConditionalOnProperty(prefix = "spring.devtools.restart", name = "enabled", matchIfMissing = true) static class RestartConfiguration { + private static final Log restarterLogger = LogFactory.getLog(Restarter.class); + private final DevToolsProperties properties; RestartConfiguration(DevToolsProperties properties) { @@ -105,6 +110,10 @@ public class LocalDevToolsAutoConfiguration { FileSystemWatcherFactory fileSystemWatcherFactory) { return (event) -> { if (event.isRestartRequired()) { + if (restarterLogger.isDebugEnabled()) { + restarterLogger.debug( + "Application restart required due to the following changes: " + event.getChangeSet()); + } Restarter.getInstance().restart(new FileWatchingFailureHandler(fileSystemWatcherFactory)); } }; diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/classpath/ClassPathFileChangeListener.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/classpath/ClassPathFileChangeListener.java index 4d6c4608e17..4339bcbffe8 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/classpath/ClassPathFileChangeListener.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/classpath/ClassPathFileChangeListener.java @@ -18,9 +18,6 @@ package org.springframework.boot.devtools.classpath; import java.util.Set; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - import org.springframework.boot.devtools.filewatch.ChangedFile; import org.springframework.boot.devtools.filewatch.ChangedFiles; import org.springframework.boot.devtools.filewatch.FileChangeListener; @@ -38,8 +35,6 @@ import org.springframework.util.Assert; */ class ClassPathFileChangeListener implements FileChangeListener { - private static final Log logger = LogFactory.getLog(ClassPathFileChangeListener.class); - private final ApplicationEventPublisher eventPublisher; private final ClassPathRestartStrategy restartStrategy; @@ -65,9 +60,6 @@ class ClassPathFileChangeListener implements FileChangeListener { @Override public void onChange(Set changeSet) { boolean restart = isRestartRequired(changeSet); - if (restart && logger.isDebugEnabled()) { - logger.debug("Restarting dev tools due to changes in the following files: " + changeSet); - } publishEvent(new ClassPathChangedEvent(this, changeSet, restart)); }