1 16 package org.apache.avalon.logging.impl; 17 18 import org.apache.avalon.framework.logger.Logger; 19 20 28 public final class ConsoleLogger 29 implements Logger 30 { 31 32 public static final int LEVEL_DEBUG = 0; 33 34 35 public static final int LEVEL_INFO = 1; 36 37 38 public static final int LEVEL_WARN = 2; 39 40 41 public static final int LEVEL_ERROR = 3; 42 43 44 public static final int LEVEL_FATAL = 4; 45 46 47 public static final int LEVEL_DISABLED = 5; 48 49 private final int m_logLevel; 50 51 54 public ConsoleLogger() 55 { 56 this( LEVEL_DEBUG ); 57 } 58 59 63 public ConsoleLogger( final int logLevel ) 64 { 65 m_logLevel = logLevel; 66 } 67 68 73 public void debug( final String message ) 74 { 75 debug( message, null ); 76 } 77 78 84 public void debug( final String message, final Throwable throwable ) 85 { 86 if( m_logLevel <= LEVEL_DEBUG ) 87 { 88 System.out.print( "[DEBUG] " ); 89 System.out.println( message ); 90 91 if( null != throwable ) 92 { 93 throwable.printStackTrace( System.out ); 94 } 95 } 96 } 97 98 103 public boolean isDebugEnabled() 104 { 105 return m_logLevel <= LEVEL_DEBUG; 106 } 107 108 113 public void info( final String message ) 114 { 115 info( message, null ); 116 } 117 118 124 public void info( final String message, final Throwable throwable ) 125 { 126 if( m_logLevel <= LEVEL_INFO ) 127 { 128 System.out.print( "[INFO] " ); 129 System.out.println( message ); 130 131 if( null != throwable ) 132 { 133 throwable.printStackTrace( System.out ); 134 } 135 } 136 } 137 138 143 public boolean isInfoEnabled() 144 { 145 return m_logLevel <= LEVEL_INFO; 146 } 147 148 153 public void warn( final String message ) 154 { 155 warn( message, null ); 156 } 157 158 164 public void warn( final String message, final Throwable throwable ) 165 { 166 if( m_logLevel <= LEVEL_WARN ) 167 { 168 System.out.print( "[WARNING] " ); 169 System.out.println( message ); 170 171 if( null != throwable ) 172 { 173 throwable.printStackTrace( System.out ); 174 } 175 } 176 } 177 178 183 public boolean isWarnEnabled() 184 { 185 return m_logLevel <= LEVEL_WARN; 186 } 187 188 193 public void error( final String message ) 194 { 195 error( message, null ); 196 } 197 198 204 public void error( final String message, final Throwable throwable ) 205 { 206 if( m_logLevel <= LEVEL_ERROR ) 207 { 208 System.out.print( "[ERROR] " ); 209 System.out.println( message ); 210 211 if( null != throwable ) 212 { 213 throwable.printStackTrace( System.out ); 214 } 215 } 216 } 217 218 223 public boolean isErrorEnabled() 224 { 225 return m_logLevel <= LEVEL_ERROR; 226 } 227 228 233 public void fatalError( final String message ) 234 { 235 fatalError( message, null ); 236 } 237 238 244 public void fatalError( final String message, final Throwable throwable ) 245 { 246 if( m_logLevel <= LEVEL_FATAL ) 247 { 248 System.out.print( "[FATAL ERROR] " ); 249 System.out.println( message ); 250 251 if( null != throwable ) 252 { 253 throwable.printStackTrace( System.out ); 254 } 255 } 256 } 257 258 263 public boolean isFatalErrorEnabled() 264 { 265 return m_logLevel <= LEVEL_FATAL; 266 } 267 268 274 public Logger getChildLogger( final String name ) 275 { 276 return this; 277 } 278 } 279 | Popular Tags |