Skip to content

Commit 9b3e4d1

Browse files
Clean up the registerd logger handlers when stopping the plugin (#311)
Signed-off-by: Jinbo Wang <[email protected]>
1 parent 6208426 commit 9b3e4d1

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JavaDebuggerServerPlugin.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public void start(BundleContext context) throws Exception {
3535
@Override
3636
public void stop(BundleContext context) throws Exception {
3737
logger.info("Stopping " + PLUGIN_ID);
38+
LogUtils.cleanupHandlers();
3839
}
3940

4041
}

com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/LogUtils.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
package com.microsoft.java.debug.plugin.internal;
1313

14+
import java.util.logging.Handler;
1415
import java.util.logging.Level;
1516
import java.util.logging.Logger;
1617

@@ -32,6 +33,21 @@ public static void initialize(Level level) {
3233
logger.setLevel(level);
3334
}
3435

36+
/**
37+
* Remove the logger handlers registered to the global logger.
38+
*/
39+
public static void cleanupHandlers() {
40+
Handler[] handlers = logger.getHandlers();
41+
for (Handler handler : handlers) {
42+
logger.removeHandler(handler);
43+
}
44+
45+
Handler[] usageHandlers = usageDataLogger.getHandlers();
46+
for (Handler handler : usageHandlers) {
47+
usageDataLogger.removeHandler(handler);
48+
}
49+
}
50+
3551
/**
3652
* Configure log level setting for java debugger.
3753
*

0 commit comments

Comments
 (0)