2019年1月9日-日志框架-小总结

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/t1g2q3/article/details/86126581
  • 日志规范
    • 为什么要使用slf4j?
      • 我们自己的系统中使用了logback这个日志系统。
        我们的系统使用了A.jar,A.jar中使用的日志系统为log4j。
        我们的系统又使用了B.jar,B.jar中使用的日志系统为slf4j-simple。
        这样,我们的系统就不得不同时支持并维护logback、log4j、slf4j-simple三种日志框架,非常不便。
      • 解决这个问题的方式就是引入一个适配层,由适配层决定使用哪一种日志系统,而调用端只需要做的事情就是打印日志而不需要关心如何打印日志,slf4j或者commons-logging就是这种适配层。
    • slf4j只是一个日志标准,并不是日志系统的具体实现。
      • slf4j只做两件事情:
        • 提供日志接口
        • 提供获取具体日志对象的方法
    • slf4j的用法(入口)
      Logger logger = LoggerFactory.getLogger(Object.class);
  • 日志冲突
    • SLF4J API is designed to bind with one and only one underlying logging framework at a time. If more than one binding is present on the class path, SLF4J will emit a warning, listing the location of those bindings.When multiple bindings are available on the class path, select one and only one binding you wish to use, and remove the other bindings. 
      • SLF4J: Class path contains multiple SLF4J bindings.
        SLF4J: Found binding in [jar:file:/xxx/learn/WEB-INF/lib/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
        SLF4J: Found binding in [jar:file:/xxx/learn/WEB-INF/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
        SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
  • 1、commons-logging  +  log4
  • 2、slf4j-api  +  logback(logback-core和logback-classic)
  • 3、commons-logging  +  jcl-over-slf4j  +  slf4j-api  +  slf4j-log4j12  +  log4j
  • 4、slf4j-api  + log4j-over-slf4j + logback(logback-core和logback-classic)

猜你喜欢

转载自blog.csdn.net/t1g2q3/article/details/86126581