问题描述
我有一个现有的应用程序,它针对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,它在这种情况下可以很好地工作,但是从他们已经删除了对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日志记录,是否有一种简单的方法可以将针对log4j发送到JUL的任何日志消息记录下来,因此我可以使用现有配置并设置来自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的javadocs,看起来我可以设置一堆环境变量来改变 LogManager
使用了实现,并且可能使用它来在JUL Logger
类中包装log4j Logger
。这是正确的方法吗?
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 Logger
s in the JUL Logger
class. Is this the correct approach?
有一种讽刺意味的是,当世界其他地方(大部分)使用内置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.
推荐答案
我成功使用的一种方法是使用作为我的主要日志记录API。然后我将slf4j绑定到log4j。使用其他框架(如JUL)的第三方依赖关系可以到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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!