1 package org.apache.ojb.broker.util.logging; 2 3 17 18 import org.apache.commons.lang.SystemUtils; 19 import org.apache.commons.lang.exception.ExceptionUtils; 20 21 28 public class StringBufferLoggerImpl extends PoorMansLoggerImpl 29 { 30 protected String EOL = SystemUtils.LINE_SEPARATOR; 31 private StringBuffer buffer; 32 private boolean errorLog; 33 34 public StringBufferLoggerImpl(String name) 35 { 36 super(name); 37 buffer = new StringBuffer (1000); 38 } 39 40 43 protected void log(String aLevel, Object obj, Throwable t) 44 { 45 buffer.append(BRAKE_OPEN).append(getName()).append(BRAKE_CLOSE).append(aLevel); 46 if (obj != null && obj instanceof Throwable ) 47 { 48 try 49 { 50 buffer.append(((Throwable ) obj).getMessage()).append(EOL); 51 ((Throwable ) obj).printStackTrace(); 52 } 53 catch (Throwable ignored) 54 { 55 56 } 57 } 58 else 59 { 60 try 61 { 62 buffer.append(obj).append(EOL); 63 } 64 catch(Exception e) 65 { 66 } 68 } 69 70 if (t != null) 71 { 72 try 73 { 74 buffer.append(t.getMessage()).append(EOL); 75 buffer.append(ExceptionUtils.getFullStackTrace(t)).append(EOL); 76 } 77 catch (Throwable ignored) 78 { 79 80 } 81 } 82 if(!errorLog && (aLevel.equals(STR_ERROR) || aLevel.equals(STR_FATAL))) 83 { 84 errorLog = true; 85 } 86 } 87 88 92 public boolean isErrorLog() 93 { 94 return errorLog; 95 } 96 97 100 public String flushLogBuffer() 101 { 102 String result = buffer.toString(); 103 buffer = new StringBuffer (1000); 104 return result; 105 } 106 } 107 | Popular Tags |