From 5cf94f83009efb72e7206393db4ba5b6ddd41936 Mon Sep 17 00:00:00 2001 From: hansonr Date: Mon, 29 Jul 2019 10:21:53 +0200 Subject: [PATCH] JAL-3778 moving Java logging to Platform. --- src/jalview/bin/Jalview.java | 44 +----------------------------- src/jalview/util/Platform.java | 59 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 43 deletions(-) diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index d9de469..a67c5fd 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -83,9 +83,6 @@ import java.util.HashMap; import java.util.Hashtable; import java.util.Map; import java.util.Vector; -import java.util.logging.ConsoleHandler; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.LookAndFeel; import javax.swing.UIManager; @@ -269,51 +266,12 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi */ public static void main(String[] args) { - // setLogging(); // BH - for event debugging in JavaScript + // Platform.startJavaLogging(); getInstance().doMain(args); } - private static void logClass(String name) - { - // BH - for event debugging in JavaScript - ConsoleHandler consoleHandler = new ConsoleHandler(); - consoleHandler.setLevel(Level.ALL); - Logger logger = Logger.getLogger(name); - logger.setLevel(Level.ALL); - logger.addHandler(consoleHandler); - } - @SuppressWarnings("unused") - private static void setLogging() - { - - /** - * @j2sIgnore - * - */ - { - System.out.println("not in js"); - } - - // BH - for event debugging in JavaScript (Java mode only) - if (!Platform.isJS()) - /** - * Java only - * - * @j2sIgnore - */ - { - Logger.getLogger("").setLevel(Level.ALL); - logClass("java.awt.EventDispatchThread"); - logClass("java.awt.EventQueue"); - logClass("java.awt.Component"); - logClass("java.awt.focus.Component"); - logClass("java.awt.focus.DefaultKeyboardFocusManager"); - } - - } - /** * @param args */ diff --git a/src/jalview/util/Platform.java b/src/jalview/util/Platform.java index fe620ed..e7be77d 100644 --- a/src/jalview/util/Platform.java +++ b/src/jalview/util/Platform.java @@ -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); + } + } + } + + } -- 1.7.10.2