如何将 java.util.logging 发送到 log4j? [英] How to send java.util.logging to log4j?

查看:47
本文介绍了如何将 java.util.logging 发送到 log4j?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的应用程序,它根据 log4j 执行所有日志记录.我们使用了许多其他库,它们也使用 log4j,或者针对 Commons Logging 进行登录,最终在我们的环境中使用 log4j.我们的一个依赖项甚至针对 slf4j 进行日志记录,这也很好用,因为它最终也委托给了 log4j.

I have an existing application which does all of its logging against log4j. We use a number of other libraries that either also use log4j, or log against Commons Logging, which ends up using log4j under the covers in our environment. One of our dependencies even logs against slf4j, which also works fine since it eventually delegates to log4j as well.

现在,我想将 ehcache 添加到此应用程序中以满足某些缓存需求.以前版本的 ehcache 使用了 commons-logging,在这种情况下它可以完美地工作,但是从 1.6-beta1 版 他们移除了对 commons-logging 的依赖,并用 java.util.logging 代替.

Now, I'd like to add ehcache to this application for some caching needs. Previous versions of ehcache used commons-logging, which would have worked perfectly in this scenario, but as of version 1.6-beta1 they have removed the dependency on commons-logging and replaced it with java.util.logging instead.

不太熟悉 java.util.logging 提供的内置 JDK 日志记录,是否有一种简单的方法可以将发送到 JUL 的任何日志消息针对 log4j 进行记录,以便我可以使用我现有的配置并进行设置是否有来自 ehcache 的日志记录?

Not really being familiar with the built-in JDK logging available with java.util.logging, is there an easy way to have any log messages sent to JUL logged against log4j, so I can use my existing configuration and set up for any logging coming from ehcache?

查看 JUL 的 javadoc,看起来我可以设置一堆环境变量来更改使用的 LogManager 实现,并且可能使用它来包装 log4j LoggerLogger 类中的 code>s.这是正确的方法吗?

Looking at the javadocs for JUL, it looks like I could set up a bunch of environment variables to change which LogManager implementation is used, and perhaps use that to wrap log4j Loggers in the JUL Logger class. Is this the correct approach?

有点讽刺的是,当世界上(大部分)其他地方正在使用 3rd 方库时,库使用内置 JDK 日志记录会导致如此头痛.

Kind of ironic that a library's use of built-in JDK logging would cause such a headache when (most of) the rest of the world is using 3rd party libraries instead.

推荐答案

我成功使用的一种方法是使用 slf4j 作为我的主要日志 API.然后我将 slf4j 绑定到 log4j.使用其他框架(如 JUL)的第 3 方依赖项可以桥接到 slf4j.

One approach I have used successfully is to use slf4j as my primary logging API. I then have slf4j bind to log4j. 3rd party dependencies using other frameworks (like JUL) can be bridged to slf4j.

这篇关于如何将 java.util.logging 发送到 log4j?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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