diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/java/JavaLoggingSystem.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/java/JavaLoggingSystem.java index a83ab4fc1e7..0b04ee77517 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/java/JavaLoggingSystem.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/java/JavaLoggingSystem.java @@ -21,6 +21,7 @@ import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.Enumeration; +import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.logging.Level; @@ -51,6 +52,8 @@ public class JavaLoggingSystem extends AbstractLoggingSystem { private static final LogLevels LEVELS = new LogLevels<>(); + private final Set configuredLoggers = Collections.synchronizedSet(new HashSet<>()); + static { LEVELS.map(LogLevel.TRACE, Level.FINEST); LEVELS.map(LogLevel.DEBUG, Level.FINE); @@ -119,6 +122,7 @@ public class JavaLoggingSystem extends AbstractLoggingSystem { } Logger logger = Logger.getLogger(loggerName); if (logger != null) { + this.configuredLoggers.add(logger); logger.setLevel(LEVELS.convertSystemToNative(level)); } } @@ -159,6 +163,11 @@ public class JavaLoggingSystem extends AbstractLoggingSystem { return new ShutdownHandler(); } + @Override + public void cleanUp() { + this.configuredLoggers.clear(); + } + private final class ShutdownHandler implements Runnable { @Override