1 19 20 21 package org.netbeans.modules.subversion; 22 23 import java.io.*; 24 25 import org.netbeans.modules.versioning.util.Utils; 26 import org.openide.ErrorManager; 27 28 33 public final class Diagnostics implements Appendable { 34 35 private static PrintWriter log; 36 37 private static String path; 38 39 public static synchronized void init() { 40 if (log != null) { 41 return; 42 } 43 path = System.getProperty("svnLog"); if (path != null && !path.trim().equals("")) { 45 try { 46 log = new PrintWriter(new OutputStreamWriter(new FileOutputStream(path), "utf8")); System.setProperty("svnClientAdapter.logger.Appendable", "org.netbeans.modules.subversion.Diagnostics"); System.err.println("Subversion diagnostics: ON"); } catch (IOException ex) { 50 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 51 } 52 } 53 } 54 55 public Diagnostics() { 56 init(); 57 } 58 59 public synchronized static void println(String msg) { 60 if (log != null) { 61 log.println(Thread.currentThread().getName() + ": " + msg); log.flush(); 63 } 64 } 65 66 public synchronized static void printTrace() { 67 if (log != null) { 68 String msg = Utils.getStackTrace(); 69 log.println(msg); 70 log.flush(); 71 } 72 } 73 74 public synchronized Appendable append(CharSequence csq) throws IOException { 75 try { 76 return log.append(Thread.currentThread().getName() + ": " + csq); } finally { 78 log.flush(); 79 } 80 } 81 82 public synchronized Appendable append(CharSequence csq, int start, int end) throws IOException { 83 try { 84 return log.append(csq, start, end); 85 } finally { 86 log.flush(); 87 } 88 89 } 90 91 public synchronized Appendable append(char c) throws IOException { 92 try { 93 return log.append(c); 94 } finally { 95 log.flush(); 96 } 97 } 98 99 public String toString() { 100 return "" + path; } 102 } 103 | Popular Tags |