Always shutdown the logger.
[Sone.git] / src / main / java / net / pterodactylus / sone / main / SonePlugin.java
index b253d41..50f17a1 100644 (file)
@@ -145,8 +145,21 @@ public class SonePlugin implements FredPlugin, FredPluginL10n, FredPluginBaseL10
                core.freenetInterface(freenetInterface);
 
                /* start core! */
-               core.start();
-               webInterface.start();
+               boolean startupFailed = true;
+               try {
+                       core.start();
+                       webInterface.start();
+                       startupFailed = false;
+               } finally {
+                       if (startupFailed) {
+                               /*
+                                * we let the exception bubble up but shut the logging down so
+                                * that the logfile is not swamped by the installed logging
+                                * handlers of the failed instances.
+                                */
+                               Logging.shutdown();
+                       }
+               }
        }
 
        /**
@@ -154,21 +167,24 @@ public class SonePlugin implements FredPlugin, FredPluginL10n, FredPluginBaseL10
         */
        @Override
        public void terminate() {
-               /* stop the web interface. */
-               webInterface.stop();
+               try {
+                       /* stop the web interface. */
+                       webInterface.stop();
 
-               /* stop the core. */
-               core.stop();
+                       /* stop the core. */
+                       core.stop();
 
-               /* TODO wait for core to stop? */
-               try {
-                       pluginRespirator.putStore(pluginStore);
-               } catch (DatabaseDisabledException dde1) {
-                       logger.log(Level.WARNING, "Could not store plugin store, database is disabled.", dde1);
-               }
+                       /* TODO wait for core to stop? */
+                       try {
+                               pluginRespirator.putStore(pluginStore);
+                       } catch (DatabaseDisabledException dde1) {
+                               logger.log(Level.WARNING, "Could not store plugin store, database is disabled.", dde1);
+                       }
 
-               /* shutdown logger. */
-               Logging.shutdown();
+               } finally {
+                       /* shutdown logger. */
+                       Logging.shutdown();
+               }
        }
 
        //