JAL-3778 moving Java logging to Platform.
[jalview.git] / src / jalview / util / Platform.java
index fe620ed..e7be77d 100644 (file)
@@ -36,6 +36,9 @@ import java.io.Reader;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Properties;
+import java.util.logging.ConsoleHandler;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 import javax.swing.SwingUtilities;
 
@@ -264,6 +267,18 @@ public class Platform
 
   public static long time, mark, set, duration;
 
+  /**
+   * typical usage:
+   * 
+   * Platform.timeCheck(null, Platform.TIME_MARK);
+   * 
+   * ...
+   * 
+   * Platform.timeCheck("some message", Platform.TIME_MARK);
+   * 
+   * @param msg
+   * @param mode
+   */
   public static void timeCheck(String msg, int mode)
   {
     long t = System.currentTimeMillis();
@@ -749,4 +764,48 @@ public class Platform
     }
   }
 
+  /**
+   * Initialize Java debug logging. A representative sample -- adapt as desired.
+   */
+  public static void startJavaLogging()
+  {
+    /**
+     * @j2sIgnore
+     */
+    {
+      logClass("java.awt.EventDispatchThread", "java.awt.EventQueue",
+              "java.awt.Component", "java.awt.focus.Component",
+              "java.awt.event.Component",
+              "java.awt.focus.DefaultKeyboardFocusManager");
+    }
+  }
+
+  /**
+   * Initiate Java logging for a given class. Only for Java, not JavaScript;
+   * Allows debugging of complex event processing.
+   * 
+   * @param className
+   */
+  public static void logClass(String... classNames)
+  {
+    /**
+     * @j2sIgnore
+     * 
+     * 
+     */
+    {
+      Logger rootLogger = Logger.getLogger("");
+      rootLogger.setLevel(Level.ALL);
+      ConsoleHandler consoleHandler = new ConsoleHandler();
+      consoleHandler.setLevel(Level.ALL);
+      for (int i = classNames.length; --i >= 0;)
+      {
+        Logger logger = Logger.getLogger(classNames[i]);
+        logger.setLevel(Level.ALL);
+        logger.addHandler(consoleHandler);
+      }
+    }
+  }
+
+
 }