1 17 package org.apache.avalon.excalibur.testcase; 18 19 import org.apache.avalon.framework.ExceptionUtil; 20 import org.apache.avalon.framework.logger.Logger; 21 22 33 public class BufferedLogger 34 implements Logger 35 { 36 private final StringBuffer m_sb = new StringBuffer (); 37 38 43 public void debug( final String message ) 44 { 45 debug( message, null ); 46 } 47 48 54 public void debug( final String message, final Throwable throwable ) 55 { 56 append( "DEBUG", message, throwable ); 57 } 58 59 64 public boolean isDebugEnabled() 65 { 66 return true; 67 } 68 69 74 public void info( final String message ) 75 { 76 info( message, null ); 77 } 78 79 85 public void info( final String message, final Throwable throwable ) 86 { 87 append( "INFO", message, throwable ); 88 } 89 90 95 public boolean isInfoEnabled() 96 { 97 return true; 98 } 99 100 105 public void warn( final String message ) 106 { 107 warn( message, null ); 108 } 109 110 116 public void warn( final String message, final Throwable throwable ) 117 { 118 append( "WARN", message, throwable ); 119 } 120 121 126 public boolean isWarnEnabled() 127 { 128 return true; 129 } 130 131 136 public void error( final String message ) 137 { 138 error( message, null ); 139 } 140 141 147 public void error( final String message, final Throwable throwable ) 148 { 149 append( "ERROR", message, throwable ); 150 } 151 152 157 public boolean isErrorEnabled() 158 { 159 return true; 160 } 161 162 167 public void fatalError( final String message ) 168 { 169 fatalError( message, null ); 170 } 171 172 178 public void fatalError( final String message, final Throwable throwable ) 179 { 180 append( "FATAL ERROR", message, throwable ); 181 } 182 183 188 public boolean isFatalErrorEnabled() 189 { 190 return true; 191 } 192 193 200 public Logger getChildLogger( final String name ) 201 { 202 return this; 203 } 204 205 211 public String toString() 212 { 213 return m_sb.toString(); 214 } 215 216 private void append( final String level, 217 final String message, 218 final Throwable throwable ) 219 { 220 synchronized( m_sb ) 221 { 222 m_sb.append( level ); 223 m_sb.append( " - " ); 224 m_sb.append( message ); 225 226 if( null != throwable ) 227 { 228 final String stackTrace = 229 ExceptionUtil.printStackTrace( throwable ); 230 m_sb.append( " : " ); 231 m_sb.append( stackTrace ); 232 } 233 m_sb.append( "\n" ); 234 } 235 } 236 } 237 | Popular Tags |