JUL到SLF4J大桥 [英] JUL to SLF4J Bridge

查看:461
本文介绍了JUL到SLF4J大桥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在观察第三方库(即restfb)正在使用java.util.logging并且我看到这些日志最终在STDOUT中,即使我没有在我的logback中配置SLF4J控制台appender .XML。我的classpath中还有 jul-to-slf4j 桥。 jul-to-slf4j网桥是否仅在安装网桥时登录到由logback配置的appender,还是记录到stdout?

I'm currently observing that a 3rd party library (namely restfb) is using java.util.logging and I'm seeing those logs end up in STDOUT even though I don't have an SLF4J console appender configured in my logback.xml. I also have the jul-to-slf4j bridge in my classpath. Does the jul-to-slf4j bridge only log to the appenders configured by logback when the bridge is installed or does it also log to stdout?

推荐答案

您需要致电 SLF4JBridgeHandler.install () 。您还需要在java.util.logging中启用根记录器上的所有日志级别(以下摘录中的原因)并删除默认控制台appender。

You need to call SLF4JBridgeHandler.install(). You also need to enable all log levels at the root logger (reason in excerpt below) in java.util.logging and remove the default console appender.


此处理程序将jul日志记录重定向到SLF4J。但是,仅在j.u.l中启用
日志。将被重定向。例如,如果日志语句
调用j.u.l.记录器禁用该语句,根据定义,
不会到达任何SLF4JBridgeHandler实例,也不能重定向。

This handler will redirect jul logging to SLF4J. However, only logs enabled in j.u.l. will be redirected. For example, if a log statement invoking a j.u.l. logger disabled that statement, by definition, will not reach any SLF4JBridgeHandler instance and cannot be redirected.

整个过程可以像这样完成

The whole process can be accomplished like so

import java.util.logging.Logger;
import org.slf4j.bridge.SLF4JBridgeHandler;

SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
Logger.getLogger("").setLevel(Level.FINEST); // Root logger, for example.

出于性能原因,您可以将级别设置为高于最高级别,但您将无法开启这些日志而不使它们在的java.util.logging 第一(上面在摘录中提到的原因)。

You can set the level to something higher than finest for performance reasons, but you won't be able to turn those logs on without enabling them in java.util.logging first (for the reason mentioned above in the excerpt).

这篇关于JUL到SLF4J大桥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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