1 33 34 package org.slf4j.impl; 35 36 37 import org.apache.log4j.Level; 38 import org.slf4j.Logger; 39 import org.slf4j.Marker; 40 import org.slf4j.helpers.MarkerIgnoringBase; 41 import org.slf4j.helpers.MessageFormatter; 42 import org.slf4j.spi.LocationAwareLogger; 43 44 45 55 public final class Log4jLoggerAdapter extends MarkerIgnoringBase implements LocationAwareLogger { 56 final org.apache.log4j.Logger logger; 57 58 62 final static String FQCN = Log4jLoggerAdapter.class.getName(); 63 64 Log4jLoggerAdapter(org.apache.log4j.Logger logger) { 67 this.logger = logger; 68 } 69 70 public String getName() { 71 return logger.getName(); 72 } 73 74 80 public boolean isTraceEnabled() { 81 return logger.isTraceEnabled(); 82 } 83 84 85 89 public void trace(String msg) { 90 logger.log(FQCN, Level.TRACE, msg, null); 91 } 92 93 103 public void trace(String format, Object arg) { 104 if (logger.isTraceEnabled()) { 105 String msgStr = MessageFormatter.format(format, arg); 106 logger.log(FQCN, Level.TRACE, msgStr, null); 107 } 108 } 109 110 121 public void trace(String format, Object arg1, Object arg2) { 122 if (logger.isTraceEnabled()) { 123 String msgStr = MessageFormatter.format(format, arg1, arg2); 124 logger.log(FQCN, Level.TRACE, msgStr, null); 125 } 126 } 127 128 138 public void trace(String format, Object [] argArray) { 139 if (logger.isTraceEnabled()) { 140 String msgStr = MessageFormatter.arrayFormat(format, argArray); 141 logger.log(FQCN, Level.TRACE, msgStr, null); 142 } 143 } 144 145 152 public void trace(String msg, Throwable t) { 153 logger.log(FQCN, Level.TRACE, msg, t); 154 } 155 156 157 163 public boolean isDebugEnabled() { 164 return logger.isDebugEnabled(); 165 } 166 167 168 172 public void debug(String msg) { 173 logger.log(FQCN, Level.DEBUG, msg, null); 174 } 175 176 186 public void debug(String format, Object arg) { 187 if (logger.isDebugEnabled()) { 188 String msgStr = MessageFormatter.format(format, arg); 189 logger.log(FQCN, Level.DEBUG, msgStr, null); 190 } 191 } 192 193 204 public void debug(String format, Object arg1, Object arg2) { 205 if (logger.isDebugEnabled()) { 206 String msgStr = MessageFormatter.format(format, arg1, arg2); 207 logger.log(FQCN, Level.DEBUG, msgStr, null); 208 } 209 } 210 211 221 public void debug(String format, Object [] argArray) { 222 if (logger.isDebugEnabled()) { 223 String msgStr = MessageFormatter.arrayFormat(format, argArray); 224 logger.log(FQCN, Level.DEBUG, msgStr, null); 225 } 226 } 227 228 235 public void debug(String msg, Throwable t) { 236 logger.log(FQCN, Level.DEBUG, msg, t); 237 } 238 239 245 public boolean isInfoEnabled() { 246 return logger.isInfoEnabled(); 247 } 248 249 254 public void info(String msg) { 255 logger.log(FQCN, Level.INFO, msg, null); 256 } 257 258 268 public void info(String format, Object arg) { 269 if (logger.isInfoEnabled()) { 270 String msgStr = MessageFormatter.format(format, arg); 271 logger.log(FQCN, Level.INFO, msgStr, null); 272 } 273 } 274 275 286 public void info(String format, Object arg1, Object arg2) { 287 if (logger.isInfoEnabled()) { 288 String msgStr = MessageFormatter.format(format, arg1, arg2); 289 logger.log(FQCN, Level.INFO, msgStr, null); 290 } 291 } 292 293 303 public void info(String format, Object [] argArray) { 304 if (logger.isInfoEnabled()) { 305 String msgStr = MessageFormatter.arrayFormat(format, argArray); 306 logger.log(FQCN, Level.INFO, msgStr, null); 307 } 308 } 309 310 317 public void info(String msg, Throwable t) { 318 logger.log(FQCN, Level.INFO, msg, t); 319 } 320 321 327 public boolean isWarnEnabled() { 328 return logger.isEnabledFor(Level.WARN); 329 } 330 331 336 public void warn(String msg) { 337 logger.log(FQCN, Level.WARN, msg, null); 338 } 339 340 350 public void warn(String format, Object arg) { 351 if (logger.isEnabledFor(Level.WARN)) { 352 String msgStr = MessageFormatter.format(format, arg); 353 logger.log(FQCN, Level.WARN, msgStr, null); 354 } 355 } 356 357 368 public void warn(String format, Object arg1, Object arg2) { 369 if (logger.isEnabledFor(Level.WARN)) { 370 String msgStr = MessageFormatter.format(format, arg1, arg2); 371 logger.log(FQCN, Level.WARN, msgStr, null); 372 } 373 } 374 375 385 public void warn(String format, Object [] argArray) { 386 if (logger.isEnabledFor(Level.WARN)) { 387 String msgStr = MessageFormatter.arrayFormat(format, argArray); 388 logger.log(FQCN, Level.WARN, msgStr, null); 389 } 390 } 391 392 393 400 public void warn(String msg, Throwable t) { 401 logger.log(FQCN, Level.WARN, msg, t); 402 } 403 404 410 public boolean isErrorEnabled() { 411 return logger.isEnabledFor(Level.ERROR); 412 } 413 414 419 public void error(String msg) { 420 logger.log(FQCN, Level.ERROR, msg, null); 421 } 422 423 433 public void error(String format, Object arg) { 434 if (logger.isEnabledFor(Level.ERROR)) { 435 String msgStr = MessageFormatter.format(format, arg); 436 logger.log(FQCN, Level.ERROR, msgStr, null); 437 } 438 } 439 440 451 public void error(String format, Object arg1, Object arg2) { 452 if (logger.isEnabledFor(Level.ERROR)) { 453 String msgStr = MessageFormatter.format(format, arg1, arg2); 454 logger.log(FQCN, Level.ERROR, msgStr, null); 455 } 456 } 457 458 468 public void error(String format, Object [] argArray) { 469 if (logger.isEnabledFor(Level.ERROR)) { 470 String msgStr = MessageFormatter.arrayFormat(format, argArray); 471 logger.log(FQCN, Level.ERROR, msgStr, null); 472 } 473 } 474 475 476 477 484 public void error(String msg, Throwable t) { 485 logger.log(FQCN, Level.ERROR, msg, t); 486 } 487 488 public void log(Marker marker, String callerFQCN, int level, String msg, Throwable t) { 489 Level log4jLevel; 490 switch(level) { 491 case LocationAwareLogger.TRACE_INT: 492 log4jLevel = Level.TRACE; 493 break; 494 case LocationAwareLogger.DEBUG_INT: 495 log4jLevel = Level.DEBUG; 496 break; 497 case LocationAwareLogger.INFO_INT: 498 log4jLevel = Level.INFO; 499 break; 500 case LocationAwareLogger.WARN_INT: 501 log4jLevel = Level.WARN; 502 break; 503 case LocationAwareLogger.ERROR_INT: 504 log4jLevel = Level.ERROR; 505 break; 506 default: 507 throw new IllegalStateException ("Level number "+level+" is not recognized."); 508 } 509 logger.log(callerFQCN, log4jLevel, msg, t); 510 } 511 } 512 | Popular Tags |