`
san_yun
  • 浏览: 2662471 次
  • 来自: 杭州
文章分类
社区版块
存档分类
最新评论

log4j-over-slf4的log4j Loger加载问题

 
阅读更多

log4j-over-slf4是通过定义和log4j同包名的org.apache.log4j.Logger来实现替换log4j的,但log4j-over-slf4怎么能确定JVM一定会加载它定义的这个Logger?

 

 

 

做了一个测试,发现在classpath中,log4j和slf4j两个包谁在前面先加载:

/home/yunpeng/.m2/repository/log4j/log4j/1.2.14/log4j-1.2.14.jar:

/home/yunpeng/.m2/repository/org/slf4j/log4j-over-slf4j/1.7.4/log4j-over-slf4j-1.7.4.jar

 

测试代码

package com.taobao.hasf.tlog.proxy.gather;

import org.apache.log4j.Logger;

public class LogGathersTester {

	public static void main(String[] args) throws InterruptedException {
		System.out.println(Boo.test);
		System.out.println(Logger.getLogger("root"));
		Thread.currentThread().join();


}

 

 测试脚本:

slf4j在前
/duitang/dist/sys/java/bin/java -Dfile.encoding=UTF-8 -classpath /duitang/dist/app/branches/tlog/tlog-proxy/target/test-classes:/duitang/dist/app/branches/tlog/tlog-proxy/target/classes:/home/yunpeng/.m2/repository/org/slf4j/slf4j-api/1.7.4/slf4j-api-1.7.4.jar:/home/yunpeng/.m2/repository/org/slf4j/log4j-over-slf4j/1.7.4/log4j-over-slf4j-1.7.4.jar:/home/yunpeng/.m2/repository/log4j/log4j/1.2.14/log4j-1.2.14.jar com.taobao.hasf.tlog.proxy.gather.LogGathersTester
hello
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.
org.apache.log4j.Logger@37dd7056
log4j在前
/duitang/dist/sys/java/bin/java -Dfile.encoding=UTF-8 -classpath /duitang/dist/app/branches/tlog/tlog-proxy/target/test-classes:/duitang/dist/app/branches/tlog/tlog-proxy/target/classes:/home/yunpeng/.m2/repository/log4j/log4j/1.2.14/log4j-1.2.14.jar:/home/yunpeng/.m2/repository/org/slf4j/slf4j-api/1.7.4/slf4j-api-1.7.4.jar:/home/yunpeng/.m2/repository/org/slf4j/log4j-over-slf4j/1.7.4/log4j-over-slf4j-1.7.4.jar: com.taobao.hasf.tlog.proxy.gather.LogGathersTester
hello
org.apache.log4j.Logger@12276af2

 

那么在tomcat容器中如何能保证一定先加载log4j-over-slf4j包中定义的Logger呢?

 

 

解决办法:

应用只依赖log4j-over-slf4j,不过有点风险,参考:http://stackoverflow.com/questions/4028703/issues-replacing-log4j-with-logback-log4j-over-slf4j-jar-shortcomings

  • 大小: 93.9 KB
分享到:
评论

相关推荐

    log4j-over-slf4j-1.7.33-API文档-中文版.zip

    赠送jar包:log4j-over-slf4j-1.7.33.jar; 赠送原API文档:log4j-over-slf4j-1.7.33-javadoc.jar; 赠送源代码:log4j-over-slf4j-1.7.33-sources.jar; 赠送Maven依赖信息文件:log4j-over-slf4j-1.7.33.pom; ...

    log4j-over-slf4j-1.7.33-API文档-中英对照版.zip

    赠送jar包:log4j-over-slf4j-1.7.33.jar; 赠送原API文档:log4j-over-slf4j-1.7.33-javadoc.jar; 赠送源代码:log4j-over-slf4j-1.7.33-sources.jar; 赠送Maven依赖信息文件:log4j-over-slf4j-1.7.33.pom; ...

    log4j-over-slf4j-1.7.25.jar

    log4j-over-slf4j-1.7.25.jar

    slf4j-1.7.21所有相关jar包

    该压缩包中包含以下内容: 1、jcl-over-slf4j-1.7.21.jar 2、jcl-over-slf4j-1.7.21-sources.jar 3、jul-to-slf4j-1.7.21.jar 4、jul-to-slf4j-1.7.21-sources.jar 5、log4j-over-slf4j-1.7.21.jar 6、log4j-over-...

    log4j.jar各个版本

    log4j-over-slf4j-1.5.6-sources.jar, log4j-over-slf4j-1.5.6.jar, log4j-over-slf4j-1.5.8-sources.jar, log4j-over-slf4j-1.5.8.jar, log4j-over-slf4j-1.6.1.jar, log4j-slf4j-impl-2.0.2-javadoc.jar, log4j-...

    log4j-over-slf4j-1.6.4.jar

    log4j-over-slf4j-1.6.4.jar

    log4j-to-slf4j-2.17.1-API文档-中文版.zip

    赠送jar包:log4j-to-slf4j-2.17.1.jar; 赠送原API文档:log4j-to-slf4j-2.17.1-javadoc.jar; 赠送源代码:log4j-to-slf4j-2.17.1-sources.jar; 赠送Maven依赖信息文件:log4j-to-slf4j-2.17.1.pom; 包含翻译后...

    最新slf4j-1.7.25.zip源码和jar包

    该压缩包中包含以下内容: 1、jcl-over-slf4j-1.7.21.jar 2、jcl-over-slf4j-1.7.21-sources.jar 3、jul-to-slf4j-1.7.21.jar 4、jul-to-slf4j-1.7.21-sources.jar 5、log4j-over-slf4j-1.7.21.jar 6、log4j-over-...

    log4j-over-slf4j-1.6.1.jar

    log4j-over-slf4j-1.6.1.jar log4j-over-slf4j-1.6.1.jar

    log4j-slf4j-impl-2.12.1-API文档-中文版.zip

    赠送jar包:log4j-slf4j-impl-2.12.1.jar; 赠送原API文档:log4j-slf4j-impl-2.12.1-javadoc.jar; 赠送源代码:log4j-slf4j-impl-2.12.1-sources.jar; 赠送Maven依赖信息文件:log4j-slf4j-impl-2.12.1.pom; ...

    log4j-to-slf4j-2.12.1-API文档-中文版.zip

    赠送jar包:log4j-to-slf4j-2.12.1.jar; 赠送原API文档:log4j-to-slf4j-2.12.1-javadoc.jar; 赠送源代码:log4j-to-slf4j-2.12.1-sources.jar; 赠送Maven依赖信息文件:log4j-to-slf4j-2.12.1.pom; 包含翻译后...

    log4j-slf4j-impl-2.12.1-API文档-中英对照版.zip

    赠送jar包:log4j-slf4j-impl-2.12.1.jar; 赠送原API文档:log4j-slf4j-impl-2.12.1-javadoc.jar; 赠送源代码:log4j-slf4j-impl-2.12.1-sources.jar; 赠送Maven依赖信息文件:log4j-slf4j-impl-2.12.1.pom; ...

    log4j-core-2.15.0.jar log4j-2.15.0-rc2

    Apache log4j2零日漏洞,根据 log4j-2.15.0-rc2 版本编译生成log4j-api-2.15.0.jar 1.解压你的jar jar xvf XXX.jar 2. 删除旧版本jar cd ./BOOT-INF/lib rm -rf log4j-api-*.jar 3. 上传新版本log4j-api-2.15.0....

    log4j-to-slf4j-2.10.0-API文档-中文版.zip

    赠送jar包:log4j-to-slf4j-2.10.0.jar; 赠送原API文档:log4j-to-slf4j-2.10.0-javadoc.jar; 赠送源代码:log4j-to-slf4j-2.10.0-sources.jar; 赠送Maven依赖信息文件:log4j-to-slf4j-2.10.0.pom; 包含翻译后...

    log4j-slf4j-impl-2.17.1-API文档-中英对照版.zip

    赠送jar包:log4j-slf4j-impl-2.17.1.jar; 赠送原API文档:log4j-slf4j-impl-2.17.1-javadoc.jar; 赠送源代码:log4j-slf4j-impl-2.17.1-sources.jar; 赠送Maven依赖信息文件:log4j-slf4j-impl-2.17.1.pom; ...

    log4j-to-slf4j-2.17.1-API文档-中英对照版.zip

    赠送jar包:log4j-to-slf4j-2.17.1.jar; 赠送原API文档:log4j-to-slf4j-2.17.1-javadoc.jar; 赠送源代码:log4j-to-slf4j-2.17.1-sources.jar; 赠送Maven依赖信息文件:log4j-to-slf4j-2.17.1.pom; 包含翻译后...

    slf4j-log4j12-1.7.25-API文档-中文版.zip

    赠送jar包:slf4j-log4j12-1.7.25.jar; 赠送原API文档:slf4j-log4j12-1.7.25-javadoc.jar; 赠送源代码:slf4j-log4j12-1.7.25-sources.jar; 赠送Maven依赖信息文件:slf4j-log4j12-1.7.25.pom; 包含翻译后的API...

    logging-log4j2-log4j-2.15.0-rc2.zip maven 资源库

    针对Log4j 2 远程代码执行漏洞,需要用到的升级资源包,适用于maven资源库,包括log4j,log4j-core,log4j-api,log4j-1.2-api,log4j-jpa等全套2.15.0 maven资源库jar包。如果是maven本地仓库使用,需要将zip包解压...

    slf4j-log4j12-1.0.jar

    slf4j-log4j12-1.0.jarslf4j-log4j12-1.0.jarslf4j-log4j12-1.0.jarslf4j-log4j12-1.0.jarslf4j-log4j12-1.0.jarslf4j-log4j12-1.0.jarslf4j-log4j12-1.0.jarslf4j-log4j12-1.0.jarslf4j-log4j12-1.0.jarslf4j-log4...

    Log4j2学习用到的jar包及apache-log4j-2.19.0-bin.zip

    分别有disruptor-3.3.4.jar(Log4j2异步日志的底层实现)、log4j-api-2.19.0.jar(log4j门面)、log4j-core-2.19.0.jar(log4j实现)、log4j-slf4j-impl-2.19.0.jar(SLF4J与Log4j绑定)、slf4j-api-1.7.30.jar(SLF...

Global site tag (gtag.js) - Google Analytics