1 19 20 21 package org.netbeans.modules.localhistory; 22 23 import java.io.*; 24 import java.text.SimpleDateFormat ; 25 import java.util.Date ; 26 import org.openide.ErrorManager; 27 28 32 public final class Diagnostics { 33 34 private static PrintWriter log; 35 36 private static String path; 37 38 public static final boolean ON; 39 40 private static final SimpleDateFormat defaultFormat = new SimpleDateFormat ("dd-MM-yyyy:HH-mm-ss.S"); 42 static { 43 path = System.getProperty("netbeans.debug.localHistoryLog"); if (path != null && !path.trim().equals("")) { 48 try { 49 log = new PrintWriter(new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(path, true)), "utf8")); System.err.println("LocalHistory diagnostics: ON"); } catch (IOException ex) { 52 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 53 log = null; 54 } 55 } 56 ON = log != null; 57 } 58 59 public Diagnostics() { 60 } 62 63 public synchronized static void println(String msg) { 64 if (log != null) { 65 StringBuffer sb = new StringBuffer (); 66 sb.append(defaultFormat.format(new Date (System.currentTimeMillis()))); 67 sb.append(":"); 68 sb.append(msg); 69 sb.append('\t'); 70 sb.append(Thread.currentThread().getName()); 71 log.println(sb.toString()); log.flush(); 73 } 74 } 75 76 public synchronized static void logCreate(File file, File storeFile, long ts, String from, String to) { 77 StringBuffer sb = new StringBuffer (); 78 sb.append("create"); 79 sb.append('\t'); 80 sb.append(file.getAbsolutePath()); 81 sb.append('\t'); 82 sb.append(storeFile.getAbsolutePath()); 83 sb.append('\t'); 84 sb.append(ts); 85 sb.append('\t'); 86 sb.append(from); 87 sb.append('\t'); 88 sb.append(to); 89 println(sb.toString()); 90 } 91 92 public synchronized static void logChange(File file, File storeFile, long ts) { 93 StringBuffer sb = new StringBuffer (); 94 sb.append("change"); 95 sb.append('\t'); 96 sb.append(file.getAbsolutePath()); 97 sb.append('\t'); 98 sb.append(storeFile.getAbsolutePath()); 99 sb.append('\t'); 100 sb.append(ts); 101 102 println(sb.toString()); 103 } 104 105 106 public synchronized static void logDelete(File file, File storeFile, long ts) { 107 StringBuffer sb = new StringBuffer (); 108 sb.append("delete"); 109 sb.append('\t'); 110 sb.append(file.getAbsolutePath()); 111 sb.append('\t'); 112 sb.append(storeFile.getAbsolutePath()); 113 sb.append('\t'); 114 sb.append(ts); 115 println(sb.toString()); 116 } 117 118 public String toString() { 119 return "" + path; } 121 } 122 | Popular Tags |