2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import java.util.Locale;
25 import jalview.log.JLogger;
26 import jalview.log.JLoggerI;
27 import jalview.log.JLoggerI.LogLevel;
28 import jalview.log.JLoggerLog4j;
29 import jalview.util.ChannelProperties;
30 import jalview.util.Log4j;
31 import jalview.util.Platform;
36 public static JLoggerLog4j log;
38 public static void debug(String message, Throwable t)
40 if (Console.initLogger())
42 log.debug(message, t);
46 System.out.println(message);
52 public static void info(String message)
54 if (Console.initLogger())
56 log.info(message, null);
60 System.out.println(message);
65 public static void trace(String message, Throwable t)
67 if (Console.initLogger())
69 log.trace(message, t);
73 System.out.println(message);
78 public static void debug(String message)
80 if (Console.initLogger())
82 log.debug(message, null);
86 System.out.println(message);
91 public static void info(String message, Throwable t)
93 if (Console.initLogger())
99 System.out.println(message);
105 public static void warn(String message)
107 if (Console.initLogger())
109 log.warn(message, null);
113 System.out.println(message);
118 public static void trace(String message)
120 if (Console.initLogger())
122 log.trace(message, null);
126 System.out.println(message);
130 public static void warn(String message, Throwable t)
132 if (Console.initLogger())
134 log.warn(message, t);
138 System.out.println(message);
144 public static void error(String message)
146 if (Console.initLogger())
148 log.error(message, null);
152 System.err.println(message);
157 public static void error(String message, Throwable t)
159 if (Console.initLogger())
161 log.error(message, t);
165 System.err.println(message);
166 t.printStackTrace(System.err);
171 public static void fatal(String message)
173 if (Console.initLogger())
175 log.fatal(message, null);
179 System.err.println(message);
184 public static void fatal(String message, Throwable t)
186 if (Console.initLogger())
188 log.fatal(message, t);
192 System.err.println(message);
193 t.printStackTrace(System.err);
198 public static boolean isDebugEnabled()
200 return log == null ? false : log.isDebugEnabled();
203 public static boolean isTraceEnabled()
205 return log == null ? false : log.isTraceEnabled();
208 public static JLogger.LogLevel getCachedLogLevel()
210 return Console.getCachedLogLevel(Cache.JALVIEWLOGLEVEL);
213 public static JLogger.LogLevel getCachedLogLevel(String key)
215 return getLogLevel(Cache.getDefault(key, "INFO"));
218 public static JLogger.LogLevel getLogLevel(String level)
220 return JLogger.toLevel(level);
223 public static JLogger getLogger()
228 public static boolean initLogger()
230 return initLogger(null);
233 public static boolean initLogger(String providedLogLevel)
241 JLogger.LogLevel logLevel = JLogger.LogLevel.INFO;
243 if (JLogger.isLevel(providedLogLevel))
245 logLevel = Console.getLogLevel(providedLogLevel);
249 logLevel = getCachedLogLevel();
252 if (!Platform.isJS())
254 if (!Jalview.quiet())
257 "Setting initial log level to " + logLevel.name());
259 Log4j.init(logLevel);
262 // is laxis used? Does getLogger do anything without a Logger object?
263 // Logger laxis = Log4j.getLogger("org.apache.axis", myLevel);
264 JLoggerLog4j.getLogger("org.apache.axis", logLevel);
266 // The main application logger
267 log = JLoggerLog4j.getLogger(Cache.JALVIEW_LOGGER_NAME, logLevel);
268 } catch (NoClassDefFoundError e)
270 System.err.println("Could not initialise the logger framework");
277 // Logging test message should go through the logger object
278 if (log.loggerExists())
279 log.debug(Console.LOGGING_TEST_MESSAGE);
280 // Tell the user that debug is enabled
281 debug(ChannelProperties.getProperty("app_name")
282 + " Debugging Output Follows.");
291 public static void setLogLevel(String logLevelString)
293 for (LogLevel logLevel : JLoggerI.LogLevel.values())
295 if (logLevel.toString().toLowerCase(Locale.ROOT)
296 .equals(logLevelString.toLowerCase(Locale.ROOT)))
298 log.setLevel(logLevel);
299 if (!Platform.isJS())
301 Log4j.init(logLevel);
303 JLoggerLog4j.getLogger("org.apache.axis", logLevel);
309 public final static String LOGGING_TEST_MESSAGE = "Logging to STDERR";