强制slf4j使用logback [英] Force slf4j to use logback

查看:110
本文介绍了强制slf4j使用logback的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有强制slf4j使用特定日志记录提供程序(在我的情况下为logback)?就像他们的文档中一样:

Is there anyway to force slf4j to use specific logging provider (logback in my case)? As in their docs:

在类路径上找到多个绑定

Multiple bindings were found on the class path

SLF4J API旨在一次绑定一个且仅一个基础日志框架.如果类路径上存在多个绑定,SLF4J将发出警告,列出这些绑定的位置. 当类路径上有多个绑定时,请选择一个且仅选择一个您要使用的绑定,然后删除其他绑定.例如,如果您在类路径上同时拥有slf4j-> simple-1.6.6.jar和slf4j-nop-1.6.6.jar,并且希望使用nop(> no-operation)绑定,则删除slf4j-类路径中的simple-1.6.6.jar.如果无法删除多余的绑定,SLF4J仍将使用一个日志记录框架/实现进行绑定.从1.6.6版开始,SLF4J将为其实际绑定的框架/实现类命名.

SLF4J API is desinged to bind with one and only one underlying logging framework at a time. If more than one binding is present on the class path, SLF4J will emit a warning, listing the location of those bindings. When multiple bindings are available on the class path, select one and only one binding you wish to use, and remove the other bindings. For example, if you have both slf4j->simple-1.6.6.jar and slf4j-nop-1.6.6.jar on the class path and you wish to use the nop (>no-operation) binding, then remove slf4j-simple-1.6.6.jar from the class path. If it is not possible to remove the superflous bindings, SLF4J will still bind with one logging framework/implementation. As of version 1.6.6, SLF4J will name the framework/implementation class it is actually bound to.

注意SLF4J发出的警告就是警告.

NOTE The warning emitted by SLF4J is just that, a warning.

在我的情况下,我在类路径中有log4j.jarslf4j-log4j12.jarlog4j-over-slf4j.jar和所有logback jar.我知道将slf4j-log4j12.jarlog4j-over-slf4j.jar放在一起是错误的,但是我的项目很大,而且查找和排除maven依赖并不总是那么简单.在这种情况下,slf4j甚至没有打印任何警告,因为我们仅使用了logback配置.我花了一天的时间才能理解这个罐子地狱.

In my case i have log4j.jar, slf4j-log4j12.jar, log4j-over-slf4j.jar and all logback jars in classpath. I know that it is error to have slf4j-log4j12.jar and log4j-over-slf4j.jar together, but my project is very big, and it is not always simple to find and exclude maven dependency. In this case slf4j even did not printed any warning, because we use only logback configs. It took me a day to understand this jar hell.

例如,我只想强制slf4j通过JVM参数使用logback,这样它就可以打印警告,将来也可以排除jars.

All i want is to force slf4j use logback via JVM argument, for example, so it can print warnings and i can exclude jars in future.

推荐答案

除了清理类路径之外,没有其他方法可以强制SLF4J与给定的实现绑定.

Other than cleaning up your class path, there is no way to force SLF4J to bind with a given implementation.

这篇关于强制slf4j使用logback的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆