1 16 package org.apache.log4j.lf5; 17 18 import java.io.IOException ; 19 import java.io.PrintWriter ; 20 import java.io.StringWriter ; 21 22 29 30 32 public abstract class LogRecord implements java.io.Serializable { 33 37 protected static long _seqCount = 0; 41 42 protected LogLevel _level; 43 protected String _message; 44 protected long _sequenceNumber; 45 protected long _millis; 46 protected String _category; 47 protected String _thread; 48 protected String _thrownStackTrace; 49 protected Throwable _thrown; 50 protected String _ndc; 51 protected String _location; 52 53 57 61 public LogRecord() { 62 super(); 63 64 _millis = System.currentTimeMillis(); 65 _category = "Debug"; 66 _message = ""; 67 _level = LogLevel.INFO; 68 _sequenceNumber = getNextId(); 69 _thread = Thread.currentThread().toString(); 70 _ndc = ""; 71 _location = ""; 72 } 73 74 78 85 public LogLevel getLevel() { 86 return (_level); 87 } 88 89 96 public void setLevel(LogLevel level) { 97 _level = level; 98 } 99 100 104 public abstract boolean isSevereLevel(); 105 106 109 public boolean hasThrown() { 110 Throwable thrown = getThrown(); 111 if (thrown == null) { 112 return false; 113 } 114 String thrownString = thrown.toString(); 115 return thrownString != null && thrownString.trim().length() != 0; 116 } 117 118 121 public boolean isFatal() { 122 return isSevereLevel() || hasThrown(); 123 } 124 125 132 public String getCategory() { 133 return (_category); 134 } 135 136 154 public void setCategory(String category) { 155 _category = category; 156 } 157 158 164 public String getMessage() { 165 return (_message); 166 } 167 168 174 public void setMessage(String message) { 175 _message = message; 176 } 177 178 186 public long getSequenceNumber() { 187 return (_sequenceNumber); 188 } 189 190 198 public void setSequenceNumber(long number) { 199 _sequenceNumber = number; 200 } 201 202 210 public long getMillis() { 211 return _millis; 212 } 213 214 221 public void setMillis(long millis) { 222 _millis = millis; 223 } 224 225 234 public String getThreadDescription() { 235 return (_thread); 236 } 237 238 247 public void setThreadDescription(String threadDescription) { 248 _thread = threadDescription; 249 } 250 251 268 public String getThrownStackTrace() { 269 return (_thrownStackTrace); 270 } 271 272 278 public void setThrownStackTrace(String trace) { 279 _thrownStackTrace = trace; 280 } 281 282 289 public Throwable getThrown() { 290 return (_thrown); 291 } 292 293 302 public void setThrown(Throwable thrown) { 303 if (thrown == null) { 304 return; 305 } 306 _thrown = thrown; 307 StringWriter sw = new StringWriter (); 308 PrintWriter out = new PrintWriter (sw); 309 thrown.printStackTrace(out); 310 out.flush(); 311 _thrownStackTrace = sw.toString(); 312 try { 313 out.close(); 314 sw.close(); 315 } catch (IOException e) { 316 } 318 out = null; 319 sw = null; 320 } 321 322 325 public String toString() { 326 StringBuffer buf = new StringBuffer (); 327 buf.append("LogRecord: [" + _level + ", " + _message + "]"); 328 return (buf.toString()); 329 } 330 331 336 public String getNDC() { 337 return _ndc; 338 } 339 340 345 public void setNDC(String ndc) { 346 _ndc = ndc; 347 } 348 349 354 public String getLocation() { 355 return _location; 356 } 357 358 363 public void setLocation(String location) { 364 _location = location; 365 } 366 367 371 public static synchronized void resetSequenceNumber() { 372 _seqCount = 0; 373 } 374 375 379 protected static synchronized long getNextId() { 380 _seqCount++; 381 return _seqCount; 382 } 383 387 391 } 392 393 394 395 | Popular Tags |