您的位置:首页 > 编程语言 > Java开发

日志系统组件框架之版本兼容性

2014-08-04 11:50 295 查看
【导读】日志系统六大组件:slf4j-log4j、slf4j-simple、slf4j-jdk14、slf4j-nop、slf4j-jcl、logback-classic;





        最近项目从 Maven 迁移至 Gradle ,在build.gradle
依赖配置中遇到日志系统版本兼容性问题(备注:Maven 中一切正常;( … );在解决过程中,随便梳理下日志系统下所有日志组件框架:slf4j-log4j、slf4j-simple、slf4j-jdk14、slf4j-nop、slf4j-jcl、logback-classic;

 

本文章从以下两方面进行描述:

日志系统六大组件介绍

六大组件各自体系与SLF4J-API版本兼容性

 


日志系统六大组件介绍

 

slf4j-log4j: 

        Binding
for log4j
version 1.2, a widely used logging framework. You also need to place log4j.jar on
your class path

slf4j-simple:

        Binding
for Simple implementation,
which outputs all events to System.err. Only messages of level INFO and higher are printed. This binding may be useful in the context of small applications.

slf4j-jdk14:

        Binding
for java.util.logging, also referred to as JDK 1.4 logging

slf4j-nop:

        Binding
for NOP,
silently discarding all logging.

slf4j-jcl:

        Binding
for Jakarta
Commons Logging. This binding will delegate all SLF4J logging to JCL.

logback-classic:

         NATIVE
IMPLEMENTATION There are also SLF4J bindings external to the SLF4J project, e.g. logback which
implements SLF4J natively. Logback’s 
ch.qos.logback.classic.Logger
 class
is a direct implementation of SLF4J’s 
org.slf4j.Logger
 interface.
Thus, using SLF4J in conjunction with logback involves strictly zero memory and computational overhead.

以上内容请到官网查看:http://www.slf4j.org/manual.html

 

 


六大组件各自体系与SLF4J-API版本兼容性

 

 





由上图可以得出:

1) slf4j-api由
两个时期版本组成

slf4j-api分为 1.5.5 和 1.5.5之前版本 及 1.5.6和1.5.6之后版本,主要不同之处:

StaticLoggerBinder.java

1.5.5 And below 1.5.5

 

1.5.6 And above 1.5.6

/**
* The unique instance of this class.
*
*/
privatestaticfinal StaticLoggerBinder SINGLETON = newStaticLoggerBinder();

/**
* Return the singleton of this class.
*
* @return the StaticLoggerBinder singleton
*/
publicstaticfinal StaticLoggerBinder getSingleton() {
returnSINGLETON;
}


 

如果日志组件框架版本与slf4j-api 不一致,很可能会抛异常:

 

 

2)slf4j-log4j、slf4j-simple、slf4j-jdk14、slf4j-nop、slf4j-jcl、logback-classic
与 slf4j-api 版本相匹配

slf4j-log4j、slf4j-simple、slf4j-jdk14、slf4j-nop、slf4j-jcl  这五大组件直接与slf4j-api 版本 相同,这个比较容易区分;

而 logback-classic  0.9.11之前 版本与 slf4j-api 1.5.5 之前 版本相对应,0.9.12之后 版本与 slf4j-api 1.5.6之后 版本相对应,这点经过本人测试得出;

 

 

 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息