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 boolean initLogger()
225 return initLogger(null);
228 public static boolean initLogger(String providedLogLevel)
236 JLogger.LogLevel logLevel = JLogger.LogLevel.INFO;
238 if (JLogger.isLevel(providedLogLevel))
239 logLevel = Console.getLogLevel(providedLogLevel);
241 logLevel = getCachedLogLevel();
243 if (!Platform.isJS())
246 .println("Setting initial log level to " + logLevel.name());
247 Log4j.init(logLevel);
250 // is laxis used? Does getLogger do anything without a Logger object?
251 // Logger laxis = Log4j.getLogger("org.apache.axis", myLevel);
252 JLoggerLog4j.getLogger("org.apache.axis", logLevel);
254 // The main application logger
255 log = JLoggerLog4j.getLogger(Cache.JALVIEW_LOGGER_NAME, logLevel);
256 } catch (NoClassDefFoundError e)
258 System.err.println("Could not initialise the logger framework");
265 // Logging test message should go through the logger object
266 if (log.loggerExists())
267 log.debug(Console.LOGGING_TEST_MESSAGE);
268 // Tell the user that debug is enabled
269 debug(ChannelProperties.getProperty("app_name")
270 + " Debugging Output Follows.");
279 public static void setLogLevel(String logLevelString)
281 for (LogLevel logLevel : JLoggerI.LogLevel.values())
283 if (logLevel.toString().toLowerCase(Locale.ROOT)
284 .equals(logLevelString.toLowerCase(Locale.ROOT)))
286 log.setLevel(logLevel);
287 if (!Platform.isJS())
289 Log4j.init(logLevel);
291 JLoggerLog4j.getLogger("org.apache.axis", logLevel);
297 public final static String LOGGING_TEST_MESSAGE = "Logging to STDERR";