1 33 34 package org.slf4j.impl; 35 36 import org.slf4j.helpers.MarkerIgnoringBase; 37 import org.slf4j.helpers.MessageFormatter; 38 39 64 public class SimpleLogger extends MarkerIgnoringBase { 65 68 private static long startTime = System.currentTimeMillis(); 69 public static final String LINE_SEPARATOR = 70 System.getProperty("line.separator"); 71 private static String INFO_STR = "INFO"; 72 private static String WARN_STR = "WARN"; 73 private static String ERROR_STR = "ERROR"; 74 String name; 75 76 80 SimpleLogger(String name) { 81 this.name = name; 82 } 83 84 public String getName() { 85 return name; 86 } 87 88 92 public boolean isTraceEnabled() { 93 return false; 94 } 95 96 100 public void trace(String msg) { 101 } 103 104 108 public void trace(String format, Object param1) { 109 } 111 112 113 117 public void trace(String format, Object param1, Object param2) { 118 } 120 121 public void trace(String format, Object [] argArray) { 122 } 124 125 129 public void trace(String msg, Throwable t) { 130 } 132 133 134 138 public boolean isDebugEnabled() { 139 return false; 140 } 141 142 146 public void debug(String msg) { 147 } 149 150 154 public void debug(String format, Object param1) { 155 } 157 158 159 163 public void debug(String format, Object param1, Object param2) { 164 } 166 167 public void debug(String format, Object [] argArray) { 168 } 170 171 175 public void debug(String msg, Throwable t) { 176 } 178 179 187 private void log(String level, String message, Throwable t) { 188 StringBuffer buf = new StringBuffer (); 189 190 long millis = System.currentTimeMillis(); 191 buf.append(millis - startTime); 192 193 buf.append(" ["); 194 buf.append(Thread.currentThread().getName()); 195 buf.append("] "); 196 197 buf.append(level); 198 buf.append(" "); 199 200 buf.append(name); 201 buf.append(" - "); 202 203 buf.append(message); 204 205 buf.append(LINE_SEPARATOR); 206 207 System.err.print(buf.toString()); 208 if (t != null) { 209 t.printStackTrace(System.err); 210 } 211 System.err.flush(); 212 } 213 214 222 private void formatAndLog( 223 String level, String format, Object arg1, Object arg2) { 224 String message = MessageFormatter.format(format, arg1, arg2); 225 log(level, message, null); 226 } 227 228 235 private void formatAndLog(String level, String format, Object [] argArray) { 236 String message = MessageFormatter.arrayFormat(format, argArray); 237 log(level, message, null); 238 } 239 240 243 public boolean isInfoEnabled() { 244 return true; 245 } 246 247 251 public void info(String msg) { 252 log(INFO_STR, msg, null); 253 } 254 255 259 public void info(String format, Object arg) { 260 formatAndLog(INFO_STR, format, arg, null); 261 } 262 263 267 public void info(String format, Object arg1, Object arg2) { 268 formatAndLog(INFO_STR, format, arg1, arg2); 269 } 270 271 275 public void info(String format, Object [] argArray) { 276 formatAndLog(INFO_STR, format, argArray); 277 } 278 279 280 283 public void info(String msg, Throwable t) { 284 log(INFO_STR, msg, t); 285 } 286 287 290 public boolean isWarnEnabled() { 291 return true; 292 } 293 294 298 public void warn(String msg) { 299 log(WARN_STR, msg, null); 300 } 301 302 306 public void warn(String format, Object arg) { 307 formatAndLog(WARN_STR, format, arg, null); 308 } 309 310 314 public void warn(String format, Object arg1, Object arg2) { 315 formatAndLog(WARN_STR, format, arg1, arg2); 316 } 317 318 322 public void warn(String format, Object [] argArray) { 323 formatAndLog(WARN_STR, format, argArray); 324 } 325 326 329 public void warn(String msg, Throwable t) { 330 log(WARN_STR, msg, t); 331 } 332 333 336 public boolean isErrorEnabled() { 337 return true; 338 } 339 340 344 public void error(String msg) { 345 log(ERROR_STR, msg, null); 346 } 347 348 352 public void error(String format, Object arg) { 353 formatAndLog(ERROR_STR, format, arg, null); 354 } 355 356 360 public void error(String format, Object arg1, Object arg2) { 361 formatAndLog(ERROR_STR, format, arg1, arg2); 362 } 363 364 368 public void error(String format, Object [] argArray) { 369 formatAndLog(ERROR_STR, format, argArray); 370 } 371 372 373 376 public void error(String msg, Throwable t) { 377 log(ERROR_STR, msg, t); 378 } 379 } 380 | Popular Tags |