From 5cdd99fc75ec12eda59f3f58719357bd4b019f73 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Thu, 5 Oct 2023 15:18:07 +0100 Subject: [PATCH] JAL-4298 Fixed initial log level to see .jalview_properties setting. Moved Java Console startup to before Desktop startup. --- src/jalview/bin/Cache.java | 15 ++++++++--- src/jalview/bin/Console.java | 28 +++++++++++---------- src/jalview/bin/Jalview.java | 11 +++----- src/jalview/gui/Console.java | 57 +++++++++++++++++++++++++++--------------- src/jalview/gui/Desktop.java | 27 ++++++++++++++------ 5 files changed, 88 insertions(+), 50 deletions(-) diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index 1abb171..a44d474 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -1663,27 +1663,36 @@ public class Cache } if (file == null || !file.exists()) { + if (file != null) + { + jalview.bin.Console + .errPrintln("Could not load bootstrap preferences file '" + + file.getPath() + "'"); + } String channelPrefsFilename = ChannelProperties .getProperty("preferences.filename"); String propertiesFilename = System.getProperty("user.home") + File.separatorChar + channelPrefsFilename; + jalview.bin.Console.errPrintln( + "Using default properties file '" + propertiesFilename + "'"); file = new File(propertiesFilename); } if (file == null || !file.exists()) + { String releasePrefsFilename = fallbackPropertiesFile; String releasePropertiesFilename = System.getProperty("user.home") + File.separatorChar + releasePrefsFilename; + jalview.bin.Console.errPrintln("Falling back to properties file '" + + releasePropertiesFilename + "'"); file = new File(releasePropertiesFilename); } - if (filename == null) - return null; if (!file.exists()) { jalview.bin.Console .errPrintln("Could not load bootstrap preferences file '" - + filename + "'"); + + file.getPath() + "'"); return null; } diff --git a/src/jalview/bin/Console.java b/src/jalview/bin/Console.java index 1b230ec..1bb8162 100644 --- a/src/jalview/bin/Console.java +++ b/src/jalview/bin/Console.java @@ -21,10 +21,8 @@ package jalview.bin; import java.io.PrintStream; -import java.util.Locale; import jalview.log.JLogger; -import jalview.log.JLoggerI; import jalview.log.JLoggerI.LogLevel; import jalview.log.JLoggerLog4j; import jalview.util.ChannelProperties; @@ -241,7 +239,7 @@ public class Console { JLogger.LogLevel logLevel = JLogger.LogLevel.INFO; - if (JLogger.isLevel(providedLogLevel)) + if (providedLogLevel != null && JLogger.isLevel(providedLogLevel)) { logLevel = Console.getLogLevel(providedLogLevel); } @@ -292,19 +290,23 @@ public class Console public static void setLogLevel(String logLevelString) { - for (LogLevel logLevel : JLoggerI.LogLevel.values()) + LogLevel l = null; + try + { + l = LogLevel.valueOf(logLevelString); + } catch (IllegalArgumentException | NullPointerException e1) + { + Console.debug("Invalid log level '" + logLevelString + "'"); + return; + } + if (l != null) { - if (logLevel.toString().toLowerCase(Locale.ROOT) - .equals(logLevelString.toLowerCase(Locale.ROOT))) + log.setLevel(l); + if (!Platform.isJS()) { - log.setLevel(logLevel); - if (!Platform.isJS()) - { - Log4j.init(logLevel); - } - JLoggerLog4j.getLogger("org.apache.axis", logLevel); - break; + Log4j.init(l); } + JLoggerLog4j.getLogger("org.apache.axis", l); } } diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index b7d15e5..18e73ed 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -642,14 +642,12 @@ public class Jalview try { Console.initLogger(); - } catch ( - - NoClassDefFoundError error) + } catch (NoClassDefFoundError error) { error.printStackTrace(); String message = "\nEssential logging libraries not found." + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview"; - Jalview.exit(message, ExitCode.OK); + Jalview.exit(message, ExitCode.NO_LOGGING); } desktop = null; @@ -1633,8 +1631,7 @@ public class Jalview PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop, "USAGESTATS", MessageManager.getString("prompt.analytics_title"), - MessageManager.getString("prompt.analytics"), - new Runnable() + MessageManager.getString("prompt.analytics"), new Runnable() { @Override public void run() @@ -1862,7 +1859,7 @@ public class Jalview // only add new ones to the end of the list (to preserve ordinal values) OK, FILE_NOT_FOUND, FILE_NOT_READABLE, NO_FILES, INVALID_FORMAT, INVALID_ARGUMENT, INVALID_VALUE, MIXED_CLI_ARGUMENTS, - ERROR_RUNNING_COMMANDS; + ERROR_RUNNING_COMMANDS, NO_LOGGING; } /****************************** diff --git a/src/jalview/gui/Console.java b/src/jalview/gui/Console.java index 6a6cb56..4600719 100644 --- a/src/jalview/gui/Console.java +++ b/src/jalview/gui/Console.java @@ -53,6 +53,7 @@ import javax.swing.JTextArea; import javax.swing.border.Border; import javax.swing.text.DefaultCaret; +import jalview.bin.Cache; import jalview.log.JLoggerI.LogLevel; import jalview.log.JLoggerLog4j; import jalview.log.JalviewAppender; @@ -106,7 +107,7 @@ public class Console extends WindowAdapter private JComboBox logLevelCombo = new JComboBox(); - protected LogLevel startingLogLevel = LogLevel.INFO; + protected LogLevel startingLogLevel = null; public Console() { @@ -147,6 +148,7 @@ public class Console extends WindowAdapter scrollPane.setBorder(noBorder); textArea.addMouseListener(new MouseAdapter() { + @Override public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) @@ -172,6 +174,7 @@ public class Console extends WindowAdapter MessageManager.getString("label.copy_to_clipboard")); copyToClipboardButton.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { copyConsoleTextToClipboard(); @@ -183,12 +186,14 @@ public class Console extends WindowAdapter private Color fg = textArea.getForeground(); + @Override public void mousePressed(MouseEvent e) { textArea.setBackground(textArea.getSelectionColor()); textArea.setForeground(textArea.getSelectedTextColor()); } + @Override public void mouseReleased(MouseEvent e) { textArea.setBackground(bg); @@ -212,11 +217,35 @@ public class Console extends WindowAdapter // logLevelCombo.addItem(LogLevel.ERROR); // logLevelCombo.addItem(LogLevel.OFF); // set startingLogLevel - startingLogLevel = jalview.bin.Console.log == null ? LogLevel.INFO - : jalview.bin.Console.log.getLevel(); + if (jalview.bin.Console.log == null) + { + try + { + startingLogLevel = LogLevel + .valueOf(Cache.getDefault(Cache.JALVIEWLOGLEVEL, null)); + } catch (IllegalArgumentException e1) + { + jalview.bin.Console.debug( + "Invalid value for preference " + Cache.JALVIEWLOGLEVEL); + } catch (NullPointerException e2) + { + // no value in preferences + } finally + { + if (startingLogLevel == null) + { + startingLogLevel = LogLevel.INFO; + } + } + } + else + { + startingLogLevel = jalview.bin.Console.log.getLevel(); + } setChosenLogLevelCombo(); logLevelCombo.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { if (jalview.bin.Console.log != null) @@ -313,7 +342,7 @@ public class Console extends WindowAdapter boolean added = false; for (int i = 0; i < logLevelCombo.getItemCount(); i++) { - LogLevel l = (LogLevel) logLevelCombo.getItemAt(i); + LogLevel l = logLevelCombo.getItemAt(i); if (l.compareTo(setLogLevel) >= 0) { logLevelCombo.insertItemAt(setLogLevel, i); @@ -475,27 +504,15 @@ public class Console extends WindowAdapter */ public Console(Desktop desktop) { - this(desktop, true); - } - - /** - * attach a console to the desktop - the desktop will open it if requested. - * - * @param desktop - * @param showjconsole - * - if true, then redirect stdout immediately - */ - public Console(Desktop desktop, boolean showjconsole) - { parent = desktop; // window name - get x,y,width, height possibly scaled - Rectangle bounds = desktop.getLastKnownDimensions("JAVA_CONSOLE_"); + Rectangle bounds = parent.getLastKnownDimensions("JAVA_CONSOLE_"); if (bounds == null) { frame = initFrame( ChannelProperties.getProperty("app_name") + " Java Console", - desktop.getWidth() / 2, desktop.getHeight() / 4, - desktop.getX(), desktop.getY()); + parent.getWidth() / 2, parent.getHeight() / 4, parent.getX(), + parent.getY()); } else { @@ -504,7 +521,7 @@ public class Console extends WindowAdapter bounds.width, bounds.height, bounds.x, bounds.y); } frame.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT)); - // desktop.add(frame); + // parent.add(frame); initConsole(false); LogLevel level = (LogLevel) logLevelCombo.getSelectedItem(); if (!Platform.isJS()) diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index e785431..47b8893 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -499,6 +499,26 @@ public class Desktop extends jalview.jbgui.GDesktop boolean selmemusage = Cache.getDefault("SHOW_MEMUSAGE", false); boolean showjconsole = Cache.getDefault("SHOW_JAVA_CONSOLE", false); + + // start dialogue queue for single dialogues + startDialogQueue(); + + if (!Platform.isJS()) + /** + * Java only + * + * @j2sIgnore + */ + { + Desktop.instance.acquireDialogQueue(); + + jconsole = new Console(this); + jconsole.setHeader(Cache.getVersionDetailsForConsole()); + showConsole(showjconsole); + + Desktop.instance.releaseDialogQueue(); + } + desktop = new MyDesktopPane(selmemusage); showMemusage.setSelected(selmemusage); @@ -545,9 +565,6 @@ public class Desktop extends jalview.jbgui.GDesktop setBounds(xPos, yPos, 900, 650); } - // start dialogue queue for single dialogues - startDialogQueue(); - if (!Platform.isJS()) /** * Java only @@ -555,10 +572,6 @@ public class Desktop extends jalview.jbgui.GDesktop * @j2sIgnore */ { - jconsole = new Console(this, showjconsole); - jconsole.setHeader(Cache.getVersionDetailsForConsole()); - showConsole(showjconsole); - showNews.setVisible(false); experimentalFeatures.setSelected(showExperimental()); -- 1.7.10.2