slf4j日志接口技术介绍

一、简介

slf4j是一个日志接口,使用了Facade设计模式,通过阅读源码发现其主要用到了类加载机制,把实现类加载到JVM中。

二、测试

  2.1 如果只引api接口包,则日志不能正常打印。报错:

 SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

   SLF4J: Defaulting to no-operation (NOP) logger implementation

   SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

2.2 如果引slf4j-api slf4j-simple两个包,则日志可以正常打印。

2.3 如果引slf4j-api、slf4j-simple和slf4j-log4j12三个包,日志可以正常打印,不过会打警告:

SLF4J: Class path contains multiple SLF4J bindings.

SLF4J: Found binding in [jar:file:/Users/yp-tc-m-2496/.m2/repository/org/slf4j/slf4j-simple/1.7.12/slf4j-simple-1.7.12.jar!/org/slf4j/impl/StaticLoggerBinder.class]

  SLF4J: Found binding in [jar:file:/Users/yp-tc-m-2496/.m2/repository/org/slf4j/slf4j-log4j12/1.7.12/slf4j-log4j12-1.7.12.jar!/org/slf4j/impl/StaticLoggerBinder.class]

  SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

   SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]

三、附

3.1 slf4j源码解读见:

http://www.cnblogs.com/xing901022/p/4149524.html

http://www.blogjava.net/DLevin/archive/2012/11/08/390991.html

3.2 类加载机制见:http://www.ibm.com/developerworks/cn/java/j-lo-classloader/

3.3 Facade模式可以百度。

四、如有问题可以留言!



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值