1 8 9 package net.sourceforge.chaperon.common; 10 11 import org.apache.commons.logging.Log; 12 13 20 public final class ConsoleLog implements Log 21 { 22 public static final int TRACE = 0; 23 public static final int DEBUG = 1; 24 public static final int INFO = 2; 25 public static final int WARN = 3; 26 public static final int ERROR = 4; 27 public static final int FATAL = 5; 28 private int level = DEBUG; 29 30 public ConsoleLog() {} 31 32 public ConsoleLog(int level) 33 { 34 this.level = level; 35 } 36 37 44 public void trace(Object message) 45 { 46 if (isTraceEnabled()) 47 { 48 System.out.print("[TRACE] "); 49 System.out.println(message); 50 } 51 } 52 53 61 public void trace(Object message, Throwable t) 62 { 63 if (isTraceEnabled()) 64 { 65 System.out.print("[TRACE] "); 66 System.out.println(message); 67 t.printStackTrace(System.out); 68 } 69 } 70 71 81 public boolean isTraceEnabled() 82 { 83 return level<=TRACE; 84 } 85 86 93 public void debug(Object message) 94 { 95 if (isDebugEnabled()) 96 { 97 System.out.print("[DEBUG] "); 98 System.out.println(message); 99 } 100 } 101 102 110 public void debug(Object message, Throwable t) 111 { 112 if (isDebugEnabled()) 113 { 114 System.out.print("[DEBUG] "); 115 System.out.println(message); 116 t.printStackTrace(System.out); 117 } 118 } 119 120 130 public boolean isDebugEnabled() 131 { 132 return level<=DEBUG; 133 } 134 135 142 public void info(Object message) 143 { 144 if (isInfoEnabled()) 145 { 146 System.out.print("[INFO] "); 147 System.out.println(message); 148 } 149 } 150 151 159 public void info(Object message, Throwable t) 160 { 161 if (isInfoEnabled()) 162 { 163 System.out.print("[INFO] "); 164 System.out.println(message); 165 t.printStackTrace(System.out); 166 } 167 } 168 169 179 public boolean isInfoEnabled() 180 { 181 return level<=INFO; 182 } 183 184 191 public void warn(Object message) 192 { 193 if (isWarnEnabled()) 194 { 195 System.out.print("[WARN] "); 196 System.out.println(message); 197 } 198 } 199 200 208 public void warn(Object message, Throwable t) 209 { 210 if (isWarnEnabled()) 211 { 212 System.out.print("[WARN] "); 213 System.out.println(message); 214 t.printStackTrace(System.out); 215 } 216 } 217 218 228 public boolean isWarnEnabled() 229 { 230 return level<=WARN; 231 } 232 233 240 public void error(Object message) 241 { 242 if (isErrorEnabled()) 243 { 244 System.out.print("[ERROR] "); 245 System.out.println(message); 246 } 247 } 248 249 257 public void error(Object message, Throwable t) 258 { 259 if (isErrorEnabled()) 260 { 261 System.out.print("[ERROR] "); 262 System.out.println(message); 263 t.printStackTrace(System.out); 264 } 265 } 266 267 277 public boolean isErrorEnabled() 278 { 279 return level<=ERROR; 280 } 281 282 289 public void fatal(Object message) 290 { 291 if (isFatalEnabled()) 292 { 293 System.out.print("[FATAL] "); 294 System.out.println(message); 295 } 296 } 297 298 306 public void fatal(Object message, Throwable t) 307 { 308 if (isFatalEnabled()) 309 { 310 System.out.print("[FATAL] "); 311 System.out.println(message); 312 t.printStackTrace(System.out); 313 } 314 } 315 316 326 public boolean isFatalEnabled() 327 { 328 return level<=FATAL; 329 } 330 } 331 | Popular Tags |