From 9b3e4d1f60add05a9f3eaf6146eff55e30546d32 Mon Sep 17 00:00:00 2001 From: Jinbo Wang Date: Wed, 27 Nov 2019 12:55:54 +0800 Subject: [PATCH] Clean up the registerd logger handlers when stopping the plugin (#311) Signed-off-by: Jinbo Wang --- .../internal/JavaDebuggerServerPlugin.java | 1 + .../java/debug/plugin/internal/LogUtils.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JavaDebuggerServerPlugin.java b/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JavaDebuggerServerPlugin.java index 9f4e723ec..975338371 100644 --- a/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JavaDebuggerServerPlugin.java +++ b/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JavaDebuggerServerPlugin.java @@ -35,6 +35,7 @@ public void start(BundleContext context) throws Exception { @Override public void stop(BundleContext context) throws Exception { logger.info("Stopping " + PLUGIN_ID); + LogUtils.cleanupHandlers(); } } diff --git a/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/LogUtils.java b/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/LogUtils.java index 16c35d859..259631d30 100644 --- a/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/LogUtils.java +++ b/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/LogUtils.java @@ -11,6 +11,7 @@ package com.microsoft.java.debug.plugin.internal; +import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.Logger; @@ -32,6 +33,21 @@ public static void initialize(Level level) { logger.setLevel(level); } + /** + * Remove the logger handlers registered to the global logger. + */ + public static void cleanupHandlers() { + Handler[] handlers = logger.getHandlers(); + for (Handler handler : handlers) { + logger.removeHandler(handler); + } + + Handler[] usageHandlers = usageDataLogger.getHandlers(); + for (Handler handler : usageHandlers) { + usageDataLogger.removeHandler(handler); + } + } + /** * Configure log level setting for java debugger. *