SLF4JImpl.java 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package cn.com.qmth.examcloud.commons.logging;
  2. import org.slf4j.Logger;
  3. import org.slf4j.LoggerFactory;
  4. import org.slf4j.spi.LocationAwareLogger;
  5. /**
  6. * slf4j
  7. *
  8. * @author WANGWEI
  9. */
  10. public class SLF4JImpl implements ExamCloudLog {
  11. /**
  12. * 属性注释
  13. */
  14. private static final String callerFQCN = SLF4JImpl.class.getName();
  15. /**
  16. * 属性注释
  17. */
  18. private static final Logger testLogger = LoggerFactory.getLogger(SLF4JImpl.class);
  19. /**
  20. * 属性注释
  21. */
  22. private LocationAwareLogger log;
  23. static {
  24. if (!(testLogger instanceof LocationAwareLogger)) {
  25. throw new UnsupportedOperationException(testLogger.getClass() + " is not a suitable logger");
  26. }
  27. }
  28. /**
  29. * 构造函数
  30. *
  31. * @param log
  32. */
  33. public SLF4JImpl(LocationAwareLogger log) {
  34. this.log = log;
  35. }
  36. /**
  37. * 构造函数
  38. */
  39. public SLF4JImpl(String loggerName) {
  40. this.log = (LocationAwareLogger) LoggerFactory.getLogger(loggerName);
  41. }
  42. @Override
  43. public boolean isDebugEnabled() {
  44. return log.isDebugEnabled();
  45. }
  46. @Override
  47. public void debug(String msg) {
  48. log.log(null, callerFQCN, LocationAwareLogger.DEBUG_INT, msg, null, null);
  49. }
  50. @Override
  51. public void debug(String msg, Throwable e) {
  52. log.log(null, callerFQCN, LocationAwareLogger.ERROR_INT, msg, null, e);
  53. }
  54. @Override
  55. public boolean isInfoEnabled() {
  56. return log.isInfoEnabled();
  57. }
  58. @Override
  59. public void info(String msg) {
  60. log.log(null, callerFQCN, LocationAwareLogger.INFO_INT, msg, null, null);
  61. }
  62. @Override
  63. public void info(String msg, Throwable t) {
  64. log.log(null, callerFQCN, LocationAwareLogger.INFO_INT, msg, null, t);
  65. }
  66. @Override
  67. public boolean isWarnEnabled() {
  68. return log.isWarnEnabled();
  69. }
  70. @Override
  71. public void warn(String msg) {
  72. log.log(null, callerFQCN, LocationAwareLogger.WARN_INT, msg, null, null);
  73. }
  74. @Override
  75. public void warn(String msg, Throwable t) {
  76. log.log(null, callerFQCN, LocationAwareLogger.WARN_INT, msg, null, t);
  77. }
  78. @Override
  79. public boolean isErrorEnabled() {
  80. return log.isErrorEnabled();
  81. }
  82. @Override
  83. public void error(String msg) {
  84. log.log(null, callerFQCN, LocationAwareLogger.ERROR_INT, msg, null, null);
  85. }
  86. @Override
  87. public void error(String msg, Throwable t) {
  88. log.log(null, callerFQCN, LocationAwareLogger.ERROR_INT, msg, null, t);
  89. }
  90. }