Skip to content

Commit

Permalink
Clean up the registerd logger handlers when stopping the plugin (#311)
Browse files Browse the repository at this point in the history
Signed-off-by: Jinbo Wang <[email protected]>
  • Loading branch information
testforstephen authored Nov 27, 2019
1 parent 6208426 commit 9b3e4d1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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.
*
Expand Down

0 comments on commit 9b3e4d1

Please sign in to comment.