public static void init() { try { Logger.writer = new FileWriter( System.getProperty("user.home") + System.getProperty("file.separator") + ".crumb" + System.getProperty("file.separator") + "crumb.log", true); Logger.writer2 = new FileWriter( System.getProperty("user.home") + System.getProperty("file.separator") + ".crumb" + System.getProperty("file.separator") + "last.log", false); Logger.writing = true; } catch (Exception e) { Logger.printErrorStack(e); Logger.severe("Could not write to log file."); Logger.writing = false; } }
public static void close() { try { if (Logger.writer != null) { Logger.writer.close(); Logger.writer = null; } if (Logger.writer2 != null) { Logger.writer2.close(); Logger.writer2 = null; } if (Logger.writer == null && Logger.writer2 == null) { Logger.writing = false; } else { throw new Exception(); } } catch (Exception e) { Logger.severe("Could not close the log file stream. Attempting again."); Logger.printErrorStack(e); Logger.close(); } }
public static void printErrorStack(Exception e) { Logger.severe(e.getMessage()); for (StackTraceElement element : e.getStackTrace()) Logger.severe(element.toString()); }