【发布时间】:2015-09-06 17:13:58
【问题描述】:
我有一个项目,我使用 log4j 进行日志记录,它曾经工作得很好。现在我不得不添加一个使用 slf4j 的依赖项,突然日志记录不再按预期工作 - 代码的某些部分忽略了我的 log4j 配置并在 Eclipse 控制台中以红色登录。
这是日志记录工作时的依赖树:
my.package.program:program-database:jar:0.3.0
+- my.package.program:program-common:jar:0.3.0:compile
| +- org.apache.commons:commons-lang3:jar:3.4:compile
| \- commons-io:commons-io:jar:2.4:compile
+- org.springframework:spring-tx:jar:4.1.0.RELEASE:compile
| \- org.springframework:spring-core:jar:4.1.0.RELEASE:compile
| \- commons-logging:commons-logging:jar:1.1.3:compile
+- org.springframework:spring-jdbc:jar:4.1.0.RELEASE:compile
+- org.jooq:jooq:jar:3.6.2:compile
+- org.jooq:jooq-meta:jar:3.6.2:compile
+- org.jooq:jooq-codegen:jar:3.6.2:compile
+- postgresql:postgresql:jar:9.1-901-1.jdbc4:compile
+- org.springframework:spring-beans:jar:4.1.0.RELEASE:compile
+- org.springframework:spring-context:jar:4.1.0.RELEASE:compile
| +- org.springframework:spring-aop:jar:4.1.0.RELEASE:compile
| | \- aopalliance:aopalliance:jar:1.0:compile
| \- org.springframework:spring-expression:jar:4.1.0.RELEASE:compile
+- org.apache.logging.log4j:log4j-api:jar:2.1:compile
+- org.apache.logging.log4j:log4j-core:jar:2.1:compile
+- org.apache.logging.log4j:log4j-1.2-api:jar:2.1:compile
+- junit:junit:jar:4.11:test
| \- org.hamcrest:hamcrest-core:jar:1.3:test
+- org.springframework:spring-test:jar:4.1.0.RELEASE:test
这是我添加 flyway 插件并破坏日志记录后的树:
my.package.program:program-database:jar:0.3.0
+- my.package.program:program-common:jar:0.3.0:compile
| +- org.apache.commons:commons-lang3:jar:3.4:compile
| \- commons-io:commons-io:jar:2.4:compile
+- org.springframework:spring-tx:jar:4.1.0.RELEASE:compile
| \- org.springframework:spring-core:jar:4.1.0.RELEASE:compile
| \- commons-logging:commons-logging:jar:1.1.3:compile
+- org.springframework:spring-jdbc:jar:4.1.0.RELEASE:compile
+- org.jooq:jooq:jar:3.6.2:compile
+- org.jooq:jooq-meta:jar:3.6.2:compile
+- org.jooq:jooq-codegen:jar:3.6.2:compile
+- postgresql:postgresql:jar:9.1-901-1.jdbc4:compile
+- org.flywaydb.flyway-test-extensions:flyway-spring-test:jar:3.2.1:test
| +- org.slf4j:slf4j-api:jar:1.5.6:test
| +- org.slf4j:slf4j-simple:jar:1.5.6:test
| +- org.flywaydb:flyway-core:jar:3.2.1:test
| \- commons-dbcp:commons-dbcp:jar:1.4:test
| \- commons-pool:commons-pool:jar:1.5.4:test
+- org.springframework:spring-beans:jar:4.1.0.RELEASE:compile
+- org.springframework:spring-context:jar:4.1.0.RELEASE:compile
| +- org.springframework:spring-aop:jar:4.1.0.RELEASE:compile
| | \- aopalliance:aopalliance:jar:1.0:compile
| \- org.springframework:spring-expression:jar:4.1.0.RELEASE:compile
+- org.apache.logging.log4j:log4j-api:jar:2.1:compile
+- org.apache.logging.log4j:log4j-core:jar:2.1:compile
+- org.apache.logging.log4j:log4j-1.2-api:jar:2.1:compile
+- junit:junit:jar:4.11:test
| \- org.hamcrest:hamcrest-core:jar:1.3:test
+- org.springframework:spring-test:jar:4.1.0.RELEASE:test
我认为问题来自这样一个事实,即 spring 包含 commons-logging 的传递依赖,并且当 flyway 引入 slf4j 时,cli 获得优先级并且我的 log4j 配置被某些库忽略(等 jooq 和 flyway 开始以红色登录)。
我尝试了这里提到的所有 3 个选项: http://www.slf4j.org/faq.html#excludingJCL 但不知何故,他们都没有工作。肯定有效果,但是在解决方案2和3之后,spring也开始登录红色了。
在尝试盲目地插入不同的 slf4j 绑定和网桥并且没有运气之后 - 我不得不承认我对日志框架的了解不足以自己提出解决方案。欢迎任何帮助和建议。
【问题讨论】:
标签: java maven log4j slf4j flyway