Prevent JUL loggers from being GCed once their level has been set

Fixes gh-17217
pull/17511/head
Andy Wilkinson 5 years ago
parent 3fb15a502b
commit 6748b20863

@ -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<Level> LEVELS = new LogLevels<>();
private final Set<Logger> 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

Loading…
Cancel
Save