最佳答案
我有一个现有的应用程序,它对 log4j 执行所有的日志记录。我们使用了许多其他库,它们也使用 log4j,或者对 Commons Logging 进行日志记录,最终在我们的环境中使用 log4j。我们的一个依赖项甚至对 slf4j 进行了日志记录,这也可以很好地工作,因为它最终也将委托给 log4j。
现在,我想将 ehcache 添加到这个应用程序中,以满足一些缓存需求。以前版本的 ehcache 使用 commons-log,在这个场景中可以很好地工作,但是从 版本1.6-beta1开始,他们移除了对 commons-log 的依赖,代之以 java.util.log。
对于 java.util.log 中可用的内置 JDK 日志记录并不是很熟悉,是否有一种简单的方法可以将任何发送到 JUL 的日志消息记录在 log4j 中,这样我就可以使用我现有的配置并设置任何来自 ehcache 的日志记录?
查看 JUL 的 javadocs,似乎我可以设置一组环境变量来更改使用哪个 LogManager
实现,或许可以使用它来在 JUL Logger
类中包装 log4j Logger
。这是正确的方法吗?
具有讽刺意味的是,当世界其他地方(大多数地方)正在使用第三方库时,库对内置 JDK 日志记录的使用会造成如此大的麻烦。