示例#1
0
文件: Logger.java 项目: Crumb/Crumb
 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;
   }
 }
示例#2
0
文件: Logger.java 项目: Crumb/Crumb
 private static void log(String message) {
   System.out.println(message);
   if (Logger.writing) {
     try {
       if (Logger.writer == null) Logger.init();
       else
         Logger.writer.write(
             new SimpleDateFormat("[d/M/y k:m:s] ").format(new Date()) + message + "\n");
       if (Logger.writer2 == null) Logger.init();
       else
         Logger.writer2.write(
             new SimpleDateFormat("[d/M/y k:m:s] ").format(new Date()) + message + "\n");
     } catch (Exception e) {
       Logger.printErrorStack(e);
     }
   }
 }
示例#3
0
文件: Logger.java 项目: Crumb/Crumb
 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();
   }
 }
示例#4
0
文件: Logger.java 项目: Crumb/Crumb
 public static void printErrorStack(Exception e) {
   Logger.severe(e.getMessage());
   for (StackTraceElement element : e.getStackTrace()) Logger.severe(element.toString());
 }
示例#5
0
文件: Logger.java 项目: Crumb/Crumb
 public static void severe(String message) {
   Logger.log("[SEVERE] " + message);
 }
示例#6
0
文件: Logger.java 项目: Crumb/Crumb
 public static void warn(String message) {
   Logger.log("[WARNING]" + message);
 }
示例#7
0
文件: Logger.java 项目: Crumb/Crumb
 public static void debug(String message) {
   if (Logger.debug) Logger.log("[DEBUG] " + message);
 }
示例#8
0
文件: Logger.java 项目: Crumb/Crumb
 public static void info(String message) {
   Logger.log("[INFO] " + message);
 }