1 22 package org.netbeans.lib.cvsclient.util; 23 24 import java.io.*; 25 26 32 public final class Logger { 33 36 private static OutputStream outLogStream; 37 38 41 private static OutputStream inLogStream; 42 43 48 private static final String LOG_PROPERTY = "cvsClientLog"; 50 53 private static boolean logging; 54 55 static { 56 setLogging(System.getProperty(LOG_PROPERTY)); 57 } 58 59 public static void setLogging(String logPath) { 60 logging = (logPath != null); 61 62 try { 63 if (logging) { 64 if (logPath.equals("system")) { outLogStream = System.err; 66 inLogStream = System.err; 67 } 68 else { 69 outLogStream = new BufferedOutputStream(new FileOutputStream(logPath + ".out")); inLogStream = new BufferedOutputStream(new FileOutputStream(logPath + ".in")); } 72 } 73 } 74 catch (IOException e) { 75 System.err.println("Unable to create log files: " + e); System.err.println("Logging DISABLED"); logging = false; 78 try { 79 if (outLogStream != null) { 80 outLogStream.close(); 81 } 82 } 83 catch (IOException ex2) { 84 } 86 87 try { 88 if (inLogStream != null) { 89 inLogStream.close(); 90 } 91 } 92 catch (IOException ex2) { 93 } 95 } 96 } 97 98 99 104 public static void logInput(byte[] received) { 105 logInput(received, 0 , received.length); 106 } 107 108 113 public static void logInput(byte[] received, int offset, int len) { 114 if (!logging) { 115 return; 116 } 117 118 try { 119 inLogStream.write(received, offset, len); 120 inLogStream.flush(); 121 } 122 catch (IOException ex) { 123 System.err.println("Could not write to log file: " + ex); System.err.println("Logging DISABLED."); logging = false; 126 } 127 } 128 129 134 public static void logInput(char received) { 135 if (!logging) { 136 return; 137 } 138 139 try { 140 inLogStream.write(received); 141 inLogStream.flush(); 142 } 143 catch (IOException ex) { 144 System.err.println("Could not write to log file: " + ex); System.err.println("Logging DISABLED."); logging = false; 147 } 148 } 149 150 155 public static void logOutput(byte[] sent) { 156 if (!logging) { 157 return; 158 } 159 160 try { 161 outLogStream.write(sent); 162 outLogStream.flush(); 163 } 164 catch (IOException ex) { 165 System.err.println("Could not write to log file: " + ex); System.err.println("Logging DISABLED."); logging = false; 168 } 169 } 170 } 171 172 | Popular Tags |