Deregister logger handlers as last thing
[Sone.git] / src / main / java / net / pterodactylus / sone / main / SonePlugin.java
index 17340b8..ffaad9f 100644 (file)
@@ -45,7 +45,6 @@ import com.google.common.eventbus.EventBus;
 import com.google.inject.AbstractModule;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
-import com.google.inject.Singleton;
 import com.google.inject.TypeLiteral;
 import com.google.inject.matcher.Matchers;
 import com.google.inject.spi.InjectionListener;
@@ -75,9 +74,10 @@ import freenet.support.api.Bucket;
  */
 public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, FredPluginBaseL10n, FredPluginThreadless, FredPluginVersioned {
 
+       private static final Logger soneLogger = getLogger("net.pterodactylus.sone");
+
        static {
                /* initialize logging. */
-               Logger soneLogger = getLogger("net.pterodactylus.sone");
                soneLogger.setUseParentHandlers(false);
                soneLogger.addHandler(new Handler() {
                        private final LoadingCache<String, Class<?>> classCache = CacheBuilder.newBuilder()
@@ -87,7 +87,7 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr
                                                        return Class.forName(key);
                                                }
                                        });
-                       
+
                        @Override
                        public void publish(LogRecord logRecord) {
                                int recordLevel = logRecord.getLevel().intValue();
@@ -116,12 +116,12 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr
        }
 
        /** The version. */
-       public static final Version VERSION = new Version(0, 9, 2);
+       public static final Version VERSION = new Version(0, 9, 3);
 
        /** The current year at time of release. */
        private static final int YEAR = 2015;
        private static final String SONE_HOMEPAGE = "USK@nwa8lHa271k2QvJ8aa0Ov7IHAV-DFOCFgmDt3X6BpCI,DuQSUZiI~agF8c-6tjsFFGuZ8eICrzWCILB60nT8KKo,AQACAAE/sone/";
-       private static final int LATEST_EDITION = 69;
+       private static final int LATEST_EDITION = 70;
 
        /** The logger. */
        private static final Logger logger = getLogger(SonePlugin.class.getName());
@@ -306,6 +306,14 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr
                        webOfTrustConnector.stop();
                } catch (Throwable t1) {
                        logger.log(Level.SEVERE, "Error while shutting down!", t1);
+               } finally {
+                       deregisterLoggerHandlers();
+               }
+       }
+
+       private void deregisterLoggerHandlers() {
+               for (Handler handler : soneLogger.getHandlers()) {
+                       soneLogger.removeHandler(handler);
                }
        }