1 55 package org.apache.avalon.framework.logger; 56 57 65 public final class ConsoleLogger 66 implements Logger 67 { 68 69 public static final int LEVEL_DEBUG = 0; 70 71 72 public static final int LEVEL_INFO = 1; 73 74 75 public static final int LEVEL_WARN = 2; 76 77 78 public static final int LEVEL_ERROR = 3; 79 80 81 public static final int LEVEL_FATAL = 4; 82 83 84 public static final int LEVEL_DISABLED = 5; 85 86 private final int m_logLevel; 87 88 91 public ConsoleLogger() 92 { 93 this( LEVEL_DEBUG ); 94 } 95 96 100 public ConsoleLogger( final int logLevel ) 101 { 102 m_logLevel = logLevel; 103 } 104 105 110 public void debug( final String message ) 111 { 112 debug( message, null ); 113 } 114 115 121 public void debug( final String message, final Throwable throwable ) 122 { 123 if( m_logLevel <= LEVEL_DEBUG ) 124 { 125 System.out.print( "[DEBUG] " ); 126 System.out.println( message ); 127 128 if( null != throwable ) 129 { 130 throwable.printStackTrace( System.out ); 131 } 132 } 133 } 134 135 140 public boolean isDebugEnabled() 141 { 142 return m_logLevel <= LEVEL_DEBUG; 143 } 144 145 150 public void info( final String message ) 151 { 152 info( message, null ); 153 } 154 155 161 public void info( final String message, final Throwable throwable ) 162 { 163 if( m_logLevel <= LEVEL_INFO ) 164 { 165 System.out.print( "[INFO] " ); 166 System.out.println( message ); 167 168 if( null != throwable ) 169 { 170 throwable.printStackTrace( System.out ); 171 } 172 } 173 } 174 175 180 public boolean isInfoEnabled() 181 { 182 return m_logLevel <= LEVEL_INFO; 183 } 184 185 190 public void warn( final String message ) 191 { 192 warn( message, null ); 193 } 194 195 201 public void warn( final String message, final Throwable throwable ) 202 { 203 if( m_logLevel <= LEVEL_WARN ) 204 { 205 System.out.print( "[WARNING] " ); 206 System.out.println( message ); 207 208 if( null != throwable ) 209 { 210 throwable.printStackTrace( System.out ); 211 } 212 } 213 } 214 215 220 public boolean isWarnEnabled() 221 { 222 return m_logLevel <= LEVEL_WARN; 223 } 224 225 230 public void error( final String message ) 231 { 232 error( message, null ); 233 } 234 235 241 public void error( final String message, final Throwable throwable ) 242 { 243 if( m_logLevel <= LEVEL_ERROR ) 244 { 245 System.out.print( "[ERROR] " ); 246 System.out.println( message ); 247 248 if( null != throwable ) 249 { 250 throwable.printStackTrace( System.out ); 251 } 252 } 253 } 254 255 260 public boolean isErrorEnabled() 261 { 262 return m_logLevel <= LEVEL_ERROR; 263 } 264 265 270 public void fatalError( final String message ) 271 { 272 fatalError( message, null ); 273 } 274 275 281 public void fatalError( final String message, final Throwable throwable ) 282 { 283 if( m_logLevel <= LEVEL_FATAL ) 284 { 285 System.out.print( "[FATAL ERROR] " ); 286 System.out.println( message ); 287 288 if( null != throwable ) 289 { 290 throwable.printStackTrace( System.out ); 291 } 292 } 293 } 294 295 300 public boolean isFatalErrorEnabled() 301 { 302 return m_logLevel <= LEVEL_FATAL; 303 } 304 305 311 public Logger getChildLogger( final String name ) 312 { 313 return this; 314 } 315 } 316 | Popular Tags |