Jetty 10 及更高版本的更新答案(2020 年 7 月)
从 Jetty 10.0.0 开始,不再有“Jetty Logging”外观。
码头项目已改为仅使用 SLF4J 2.0 https://github.com/eclipse/jetty.project/issues/4572.
Jetty 9 及更早版本的原始答案
该文档是正确的,因为术语“Java 日志框架”通常与现代日志框架相关联,如 java.util.logging、slf4j、logback、log4j、commons-logging、logkit 等。
这是正确的,Jetty 不使用其中任何一个。
Jetty 日志记录早于ALL标准化日志框架方面的努力。 (Jetty 及其日志记录层创建于 1995 年)
这就是 Jetty 日志记录的作用(并且已记录 https://www.eclipse.org/jetty/documentation/jetty-9/index.html#configuring-logging有关设置和配置的信息,请参阅文档站点。
默认行为:
- If slf4j http://slf4j.org/存在于您的类路径中,它将向 slf4j 发出日志记录事件以使用Slf4jLog https://www.eclipse.org/jetty/javadoc/jetty-9/org/eclipse/jetty/util/log/Slf4jLog.html处理程序。
- 回退到标准错误日志 https://www.eclipse.org/jetty/javadoc/jetty-9/org/eclipse/jetty/util/log/StdErrLog.html,发送至 System.err。
配置:
- Specify the logging implementation you want it to use.
Choices are:
- 标准错误日志 https://www.eclipse.org/jetty/javadoc/jetty-9/org/eclipse/jetty/util/log/StdErrLog.html
- Slf4jLog https://www.eclipse.org/jetty/javadoc/jetty-9/org/eclipse/jetty/util/log/Slf4jLog.html
- Java实用程序日志 https://www.eclipse.org/jetty/javadoc/jetty-9/org/eclipse/jetty/util/log/JavaUtilLog.html
这可以通过 3 种不同的方式来完成
- 使用系统属性来设置日志记录实现
# 3 different options
-Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
-Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.Slf4jLog
-Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.JavaUtilLog
- 使用
jetty-logging.properties
从类路径中找到的自我发现/配置。
jetty 项目本身的示例 https://github.com/eclipse/jetty.project/blob/jetty-9.2.3.v20140905/jetty-websocket/websocket-common/src/test/resources/jetty-logging.properties:
# Configure for System.err output
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
# Configure StdErrLog to log all jetty namespace at default of WARN or above
org.eclipse.jetty.LEVEL=WARN
# Configure StdErrLog to log websocket specific namespace at DEBUG or above
org.eclipse.jetty.websocket.LEVEL=DEBUG
- 使用代码来设置Log.setLog(Logger) https://www.eclipse.org/jetty/javadoc/jetty-9/org/eclipse/jetty/util/log/Log.html#setLog(org.eclipse.jetty.util.log.Logger)
这对于那些使用嵌入式码头 /questions/tagged/embedded-jetty
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.StdErrLog;
Log.setLog(new StdErrLog());
建议和注意事项:
Jetty 服务器启动的输出将为您提供有关其正在使用的日志记录实现的提示。
正常/默认行为:
2014-09-11 10:48:38.726:INFO::main: Logging initialized @378ms
2014-09-11 10:48:39.067:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:/Users/joakim/Code/Jetty/distros/jetty-distribution-9.2.1.v20140609/demo-base/webapps/] at interval 1
请注意,它的输出中要么没有命名空间声明,要么有大量缩写的命名空间。这告诉我,StdErrLog
正在使用中。
如果正在使用 slf4j:
10:50:18.871 [main] INFO org.eclipse.jetty.util.log - Logging initialized @352ms
10:50:19.102 [main] INFO o.e.j.d.p.ScanningAppProvider - Deployment monitor [file:/Users/joakim/Code/Jetty/distros/jetty-distribution-9.2.1.v20140609/demo-base/webapps/] at interval 1
这是默认值控制台附加器 http://logback.qos.ch/manual/configuration.html输出为slf4j
-> logback
。这里的整体结构与StdErrLog
产生,所以我现在可以知道码头正在通过Slf4jLog
执行。