/tests/Fest/src/org/gjt/sp/jedit/testframework/Log.java
Java | 64 lines | 27 code | 7 blank | 30 comment | 1 complexity | 0da07f957e3f267b3edd94e78d419936 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
- package org.gjt.sp.jedit.testframework;
- import java.io.*;
- import java.util.*;
- /**
- * Simple logger for debugging, useful for web app components that don't have
- * access to the servlet container log. All exceptions that could possibly be
- * caught are caught and silently ignored so as to not cause an application
- * failure.
- * <p>
- * The specific log file may be set by setting a System property named "LOG_FILE".
- * Of course, the file must be writable, or there will be a problem! If this
- * property is not set, the log file will be written to $user.home/debug.txt.
- * <p>
- * The log file will always be appended to, never overwritten.
- *
- * @author Dale Anson
- */
- public class Log {
- private static File logfile = System.getProperty("LOG_FILE") != null ?
- new File(System.getProperty("LOG_FILE")) :
- new File(System.getProperty("user.home"), "jedit_debug.txt");
- /**
- * Write a message to the log file.
- *
- * @param msg the message to write.
- */
- public static void log(String msg) {
- try {
- FileWriter fw = new FileWriter(logfile, true);
- fw.write(new Date().toString() + ": " + msg + "\n");
- fw.flush();
- fw.close();
- }
- catch (Exception e) {
- }
- }
- /**
- * Write an exception to the log file. This will write out the full stack
- * trace, not just the message.
- *
- * @param e The exception to log.
- */
- public static void log(Exception e) {
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- e.printStackTrace(pw);
- log(sw.toString());
- }
- /**
- * Convenience method to log a StringBuffer to the log.
- *
- * @param sb The StringBuffer containing the message to write to the log.
- */
- public static void log(StringBuffer sb) {
- log(sb.toString());
- }
- }