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 JLogger.toLevel(Cache.getDefault(key, "INFO"));
218 public static boolean initLogger()
226 JLogger.LogLevel cachedLevel = getCachedLogLevel();
227 if (!Platform.isJS())
229 Log4j.init(cachedLevel);
232 // is laxis used? Does getLogger do anything without a Logger object?
233 // Logger laxis = Log4j.getLogger("org.apache.axis", myLevel);
234 JLoggerLog4j.getLogger("org.apache.axis", cachedLevel);
236 // The main application logger
237 log = JLoggerLog4j.getLogger(Cache.JALVIEW_LOGGER_NAME, cachedLevel);
238 } catch (NoClassDefFoundError e)
240 System.err.println("Could not initialise the logger framework");
247 // Logging test message should go through the logger object
248 if (log.loggerExists())
249 log.debug(Console.LOGGING_TEST_MESSAGE);
250 // Tell the user that debug is enabled
251 debug(ChannelProperties.getProperty("app_name")
252 + " Debugging Output Follows.");
261 public static void setLogLevel(String logLevelString)
263 for (LogLevel logLevel : JLoggerI.LogLevel.values())
265 if (logLevel.toString().toLowerCase(Locale.ROOT)
266 .equals(logLevelString.toLowerCase(Locale.ROOT)))
268 log.setLevel(logLevel);
269 if (!Platform.isJS())
271 Log4j.init(logLevel);
273 JLoggerLog4j.getLogger("org.apache.axis", logLevel);
279 public final static String LOGGING_TEST_MESSAGE = "Logging to STDERR";