1 23 24 28 50 package com.sun.jts.CosTransactions; 51 52 54 import java.io.*; 55 import java.util.*; 56 import java.text.DateFormat ; 57 58 67 74 public class ErrorLog extends Object { 75 77 private static Messages messages = null; 78 79 81 static final String DEFAULT_LOGFILE = "jts.log"; 82 83 85 private static String errorLogPath = null; 86 87 89 private static String serverName = null; 90 91 99 private static final void setup() { 100 102 int[] result = new int[1]; 103 errorLogPath = Configuration.getDirectory(Configuration.TRACE_DIRECTORY, 104 Configuration.JTS_SUBDIRECTORY, 105 result); 106 107 109 if( result[0] == Configuration.DEFAULT_USED || 110 result[0] == Configuration.DEFAULT_INVALID ) { 111 112 115 boolean loggingOn = 116 Configuration.getPropertyValue(Configuration.ERR_LOGGING) 117 != null; 118 119 if (errorLogPath != null && loggingOn) { 120 System.err.println( 121 ErrorLog.getMessage(Messages.INVALID_LOG_PATH, 122 new java.lang.Object [] 123 { errorLogPath }) 124 ); 125 } 126 127 130 if( result[0] == Configuration.DEFAULT_INVALID ) { 131 if (loggingOn) { 132 System.err.println( 133 ErrorLog.getMessage(Messages.INVALID_DEFAULT_LOG_PATH) 134 ); 135 } 136 errorLogPath = "."; 137 } 138 } 139 140 142 serverName = Configuration.getServerName(); 143 if( serverName == null ) 144 serverName = "Anonymous transient server"; 145 146 148 messages = (Messages)ResourceBundle.getBundle("com.sun.jts.CosTransactions.Messages"); 149 } 150 151 159 private static final void fileWrite( String message ) { 160 if (Configuration.getPropertyValue(Configuration.ERR_LOGGING) == null) { 161 return; 162 } 163 164 166 try { 167 File errFileHandle = new File(errorLogPath, DEFAULT_LOGFILE); 168 RandomAccessFile fileOutput = new RandomAccessFile(errFileHandle,"rw"); 169 fileOutput.seek(fileOutput.length()); 170 fileOutput.writeBytes(message); 171 fileOutput.close(); 172 } catch( Throwable e ) { 173 System.err.println( 174 ErrorLog.getMessage(Messages.LOG_FILE_WRITE_ERROR) 175 ); 176 } 177 } 178 179 193 public static final void error(int message, Object [] inserts, 194 boolean fatal) { 195 String messageStr = getMessage(message, inserts); 196 197 199 System.err.println( 200 ErrorLog.getMessage(Messages.MSG_JTS_ERROR, 201 new java.lang.Object [] { messageStr }) 202 ); 203 (new Exception ()).printStackTrace(); 204 205 212 String dateString = DateFormat.getDateTimeInstance().format(new Date()); 213 messageStr = ErrorLog.getMessage(Messages.LOG_MESSAGE, 214 new java.lang.Object [] { 215 dateString, serverName, 216 messages.getMessageNumber(message), 217 (fatal ? "F" : "E"), 218 messageStr, 219 }); 220 221 fileWrite(messageStr); 222 223 225 if (fatal) { 226 229 throw new org.omg.CORBA.INTERNAL (messageStr); 233 } 234 } 235 236 249 public static final void warning(int message, Object [] inserts) { 250 String messageStr = getMessage(message, inserts); 251 252 254 System.err.println( 255 ErrorLog.getMessage(Messages.MSG_JTS_WARNING, 256 new java.lang.Object [] { messageStr }) 257 ); 258 259 265 String dateString = DateFormat.getDateTimeInstance().format(new Date()); 266 messageStr = ErrorLog.getMessage(Messages.LOG_MESSAGE, 267 new java.lang.Object [] { 268 dateString, serverName, 269 messages.getMessageNumber(message), 270 "W", messageStr, 271 }); 272 fileWrite(messageStr); 273 } 274 275 288 public static final void info(int message, Object [] inserts) { 289 String messageStr = getMessage(message, inserts); 290 291 293 System.err.println( 294 ErrorLog.getMessage(Messages.MSG_JTS_INFO, 295 new java.lang.Object [] { messageStr }) 296 ); 297 298 304 String dateString = DateFormat.getDateTimeInstance().format(new Date()); 305 messageStr = ErrorLog.getMessage(Messages.LOG_MESSAGE, 306 new java.lang.Object [] { 307 dateString, serverName, 308 messages.getMessageNumber(message), 309 "I", messageStr, 310 }); 311 fileWrite(messageStr); 312 } 313 314 327 static final String getMessage(int message, Object [] inserts) { 328 String result = null; 329 330 332 if (errorLogPath == null) { 333 setup(); 334 } 335 336 338 if (inserts == null) { 339 inserts = new Object [0]; 340 } 341 342 return messages.getMessage(message, inserts); 343 } 344 345 354 public static final String getMessage(int messageNum) { 355 String result = null; 356 357 359 if (errorLogPath == null) { 360 setup(); 361 } 362 363 return messages.getMessage(messageNum); 364 } 365 } 366 | Popular Tags |