有没有可能对java.util.logging.Logger
进行典型的调用,并使用SLF4J将其路由到Logback?这会很好,因为我不需要逐行重构旧的jul代码。
例如,假设我们有这样一行:
private static Logger logger = Logger.getLogger(MahClass.class.getName());
//...
logger.info("blah blah blah");
如果能将其配置为通过SLF4J调用,那会很好。
发布于 2013-12-06 02:00:18
这非常简单,而且不再是性能问题。
SLF4J manual中记录了两种方法。在Javadocs中也有一些精确的例子
将jul- to -slf4j.jar添加到您的类路径中。或者通过maven依赖:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>1.7.0</version>
</dependency>
如果您没有logging.properties (用于java.util.logging),请将以下代码添加到引导程序代码中:
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
如果您有logging.properties (并希望保留它),请添加以下内容:
handlers = org.slf4j.bridge.SLF4JBridgeHandler
为了避免性能损失,请将此contextListener添加到logback.xml (从logback版本0.9.25开始):
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
<!-- reset all previous level configurations of all j.u.l. loggers -->
<resetJUL>true</resetJUL>
</contextListener>
...
</configuration>
https://stackoverflow.com/questions/6020545
复制相似问题