一次调试无法打印日志问题经历

 问题产生的现象是:storm任务启动后无日志输出(指的是$STORM_HOME/logs下无对应日志)

控制台输出如下:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/vipshop/platform/storm-0.9.0.1/lib/logback-classic-1.0.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/dcli/workspace/run-jobs/vip_storm_trfcstat-1.0-SNAPSHOT-jar-with-dependencies.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
Running: java -client -Dstorm.options=xxxx

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/vipshop/platform/storm-0.9.0.1/lib/logback-classic-1.0.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/dcli/workspace/run-jobs/vip_storm_trfcstat-1.0-SNAPSHOT-jar-with-dependencies.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
run remote mode
xxxx


根据SLF4J给出的warning信息,很容易定位问题是绑定了多个SLF4J对象
可是官网也说了,如果绑定多个的话,org/slf4j/impl/StaticLoggerBinder会挑选一个进行绑定为什么还会出错呢?
刚开始是先解决问题,在我的项目中除了storm的项目外其他使用日志服务都加上了:

<exclusion>
                    <groupId>log4j</groupId>
                    <artifactId>log4j</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                    </exclusion>


加上后日志可以正常打印
但是控制台输出还是有 mutilple bindings的日志
------------------------------------------------------
后来得空后,为了搞清楚为什么打不出日志,所以看了下当时分支的dependency tree


无法打印的branch 名称:debug-log

稍微整理了下,大概是这样
dpcommon
  +hbase
log4j:log4j:jar:1.2.17:compile
org.slf4j:slf4j-log4j12:jar:1.4.3:compile

storm_core
  +kafka
org.slf4j:slf4j-simple:jar:1.6.4:compile

storm
  +storm
+- org.slf4j:log4j-over-slf4j:jar:1.6.6:provided
+- org.slf4j:slf4j-api:jar:1.6.5:provided (scope not updated to compile)
+- ch.qos.logback:logback-classic:jar:1.0.6:provided
|  \- ch.qos.logback:logback-core:jar:1.0.6:provided

因为加入CLASSPATH的还有$STORM_HOME/lib(使用storm版本0.9.0.1),发现如下文件
log4j-over-slf4j-1.6.6.jar
slf4j-api-1.6.5.jar
同时 logback-classic-1.0.6.jar也引用了slf4j的依赖
看到这里,得出:应该是引用依赖的版本出现冲突,可能是随机选择的版本是低版本,无对应的接口,所以日志无法打印

同时,根据依赖树增加了exclusion
<exclusion>
                    <groupId>log4j</groupId>
                    <artifactId>log4j</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                    </exclusion>
                    <exclusion>
                         <groupId>org.slf4j</groupId>
                         <artifactId>slf4j-api</artifactId>
                    </exclusion>
                    <exclusion>
                         <groupId>org.slf4j</groupId>
                         <artifactId>slf4j-simple</artifactId>
                    </exclusion>



这样程序运行时无warning出现。




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值