gpt4 book ai didi

java - 将 log4j 2.10.0 与 Java 9 System.Logger 一起使用

转载 作者:搜寻专家 更新时间:2023-10-31 19:31:56 24 4
gpt4 key购买 nike

如何设置 Java 9 以便 System.Logger 实例写入 log4j 2.10.0,而不是写入 JUL?

最佳答案

这是您引用的段落:

This release contains the first support of Java 9 as well as bugfixes and minor enhancements. The Log4j API was modified to use java.util.ServiceLoader to locate Log4j implementations, although the former binding mechanism is still supported. The Log4j jar is now a multi-release jar to provide implementations of the Java 9 specific classes.

它没有提到 System.LoggerFinder 并且实际上是对 the repo 的全文搜索(2.10 版)没有提及“LoggerFinder”,也没有提到“java.lang.System”。因此,我确定 Log4J 2.10 尚未与 JEP 264: Platform Logging API and Service 集成.

发行说明似乎指的是 Log4J 现在在寻找 它自己的 API 的实现时使用 ServiceLoader API。

自己做

如果您真的需要/希望 Log4J 记录这些消息,您可以推出自己的适配器 as I did here for SLF4J .您所需要的只是 System.LoggerSystem.LoggerFinder 的 Log4J 适配器(如果您略过一些细节,两者都可以直接实现)和 META- INF/services 文件或如下所示的模块声明:

module org.slf4j.platform {
// put the right module name here
requires log4j;
provides java.lang.System.LoggerFinder
// put the right class name here
with org.log4J.Log4JSystemLoggerFinder;
}

然后使用该工件启动您的应用程序将导致 Log4J 获取平台日志消息。

关于java - 将 log4j 2.10.0 与 Java 9 System.Logger 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48108517/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com