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 jalview.log.JLogger;
24 import jalview.log.JLoggerI.LogLevel;
25 import jalview.log.JLoggerLog4j;
26 import jalview.util.ChannelProperties;
27 import jalview.util.Log4j;
28 import jalview.util.Platform;
33 public static JLoggerLog4j log=null;
35 public static void debug(String message, Throwable t)
37 if (Console.initLogger())
39 log.debug(message, t);
43 System.out.println(message);
49 public static void info(String message)
51 if (Console.initLogger())
53 log.info(message, null);
57 System.out.println(message);
62 public static void trace(String message, Throwable t)
64 if (Console.initLogger())
66 log.trace(message, t);
70 System.out.println(message);
75 public static void debug(String message)
77 if (Console.initLogger())
79 log.debug(message, null);
83 System.out.println(message);
88 public static void info(String message, Throwable t)
90 if (Console.initLogger())
96 System.out.println(message);
102 public static void warn(String message)
104 if (Console.initLogger())
106 log.warn(message, null);
110 System.out.println(message);
115 public static void trace(String message)
117 if (Console.initLogger())
119 log.trace(message, null);
123 System.out.println(message);
127 public static void warn(String message, Throwable t)
129 if (Console.initLogger())
131 log.warn(message, t);
135 System.out.println(message);
141 public static void error(String message)
143 if (Console.initLogger())
145 log.error(message, null);
149 System.err.println(message);
154 public static void error(String message, Throwable t)
156 if (Console.initLogger())
158 log.error(message, t);
162 System.err.println(message);
163 t.printStackTrace(System.err);
168 public static void fatal(String message)
170 if (Console.initLogger())
172 log.fatal(message, null);
176 System.err.println(message);
181 public static void fatal(String message, Throwable t)
183 if (Console.initLogger())
185 log.fatal(message, t);
189 System.err.println(message);
190 t.printStackTrace(System.err);
195 public static boolean isDebugEnabled()
197 return log == null ? false : log.isDebugEnabled();
200 public static boolean isTraceEnabled()
202 return log == null ? false : log.isTraceEnabled();
205 public static JLogger.LogLevel getCachedLogLevel()
207 return Console.getCachedLogLevel(Cache.JALVIEWLOGLEVEL);
210 public static JLogger.LogLevel getCachedLogLevel(String key)
212 return JLogger.toLevel(Cache.getDefault(key, "INFO"));
215 public static boolean initLogger()
223 JLogger.LogLevel cachedLevel=null;
224 if (System.getProperty("jalview.loglevel")!=null)
226 cachedLevel = JLogger.LogLevel.valueOf(System.getProperty("jalview.loglevel"));
228 if (cachedLevel==null) {
229 cachedLevel = getCachedLogLevel();
231 if (!Platform.isJS())
233 Log4j.init(cachedLevel);
236 // is laxis used? Does getLogger do anything without a Logger object?
237 // Logger laxis = Log4j.getLogger("org.apache.axis", myLevel);
238 JLoggerLog4j.getLogger("org.apache.axis", cachedLevel);
240 // The main application logger
241 log = JLoggerLog4j.getLogger(Cache.JALVIEW_LOGGER_NAME, cachedLevel);
242 log.info("Logging initialised at level: "+cachedLevel);
243 } catch (NoClassDefFoundError e)
245 System.err.println("Could not initialise the logger framework");
252 // Logging test message should got through the logger object
253 if (log.loggerExists())
254 log.debug(Console.LOGGING_TEST_MESSAGE);
255 // Tell the user that debug is enabled
256 debug(ChannelProperties.getProperty("app_name")
257 + " Debugging Output Follows.");
266 public final static String LOGGING_TEST_MESSAGE = "Logging to STDERR";