使用 SLF4J 发送/重定向/路由 java.util.logging.Logger (JUL) 到 Logback?
是否可以对 java.util.logging.Logger 进行典型调用并使用 SLF4J 将其路由到 Logback?这会很好,因为我不必逐行重构旧的 jul 代码。
EG,假设我们有这一行:
private static Logger logger = Logger.getLogger(MahClass.class.getName());
//...
logger.info("blah blah blah");
将其配置为通过 SLF4J 调用会很好。
Is it possible to have a typical call to java.util.logging.Logger
and have it route to Logback using SLF4J? This would be nice since I wouldn't have to refactor the old jul code line by line.
EG, say we have this line:
private static Logger logger = Logger.getLogger(MahClass.class.getName());
//...
logger.info("blah blah blah");
It would be nice to configure this to call through SLF4J.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这非常简单,不再是性能问题。
SLF4J 手册中记录了两种方法。 Javadocs 中也有精确的示例
添加 jul-to- slf4j.jar 到您的类路径。或者通过 Maven 依赖项:
如果您没有logging.properties(对于java.util.logging),请将其添加到您的引导代码中:
如果您有logging.properties(并且想要保留它),请将其添加到
其中 :为了避免性能损失,请将此 contextListener 添加到 logback.xml (从 logback 版本 0.9.25 开始):
It's very easy and not a performance issue anymore.
There are two ways documented in the SLF4J manual. There are also precise examples in the Javadocs
Add jul-to-slf4j.jar to your classpath. Or through maven dependency:
If you don't have logging.properties (for java.util.logging), add this to your bootstrap code:
If you have logging.properties (and want to keep it), add this to it:
In order to avoid performance penalty, add this contextListener to logback.xml (as of logback version 0.9.25):