1 17 package org.apache.avalon.excalibur.thread.impl.test; 18 19 import org.apache.avalon.framework.ExceptionUtil; 20 import org.apache.avalon.framework.logger.Logger; 21 22 31 public class BufferedLogger 32 implements Logger 33 { 34 private final StringBuffer m_sb = new StringBuffer (); 35 36 41 public void debug( final String message ) 42 { 43 debug( message, null ); 44 } 45 46 52 public void debug( final String message, final Throwable throwable ) 53 { 54 append( "DEBUG", message, throwable ); 55 } 56 57 62 public boolean isDebugEnabled() 63 { 64 return true; 65 } 66 67 72 public void info( final String message ) 73 { 74 info( message, null ); 75 } 76 77 83 public void info( final String message, final Throwable throwable ) 84 { 85 append( "INFO", message, throwable ); 86 } 87 88 93 public boolean isInfoEnabled() 94 { 95 return true; 96 } 97 98 103 public void warn( final String message ) 104 { 105 warn( message, null ); 106 } 107 108 114 public void warn( final String message, final Throwable throwable ) 115 { 116 append( "WARN", message, throwable ); 117 } 118 119 124 public boolean isWarnEnabled() 125 { 126 return true; 127 } 128 129 134 public void error( final String message ) 135 { 136 error( message, null ); 137 } 138 139 145 public void error( final String message, final Throwable throwable ) 146 { 147 append( "ERROR", message, throwable ); 148 } 149 150 155 public boolean isErrorEnabled() 156 { 157 return true; 158 } 159 160 165 public void fatalError( final String message ) 166 { 167 fatalError( message, null ); 168 } 169 170 176 public void fatalError( final String message, final Throwable throwable ) 177 { 178 append( "FATAL ERROR", message, throwable ); 179 } 180 181 186 public boolean isFatalErrorEnabled() 187 { 188 return true; 189 } 190 191 198 public Logger getChildLogger( final String name ) 199 { 200 return this; 201 } 202 203 209 public String toString() 210 { 211 return m_sb.toString(); 212 } 213 214 private void append( final String level, 215 final String message, 216 final Throwable throwable ) 217 { 218 synchronized( m_sb ) 219 { 220 m_sb.append( level ); 221 m_sb.append( " - " ); 222 m_sb.append( message ); 223 224 if( null != throwable ) 225 { 226 final String stackTrace = 227 ExceptionUtil.printStackTrace( throwable ); 228 m_sb.append( " : " ); 229 m_sb.append( stackTrace ); 230 } 231 m_sb.append( "\n" ); 232 } 233 } 234 } 235 | Popular Tags |