如何在jetty中启用日志记录?

我正在尝试调试我的情况,其中简单的ActiveWeb应用程序未在Jetty下运行。 它表现得好像没有任何用于请求处理的类并返回错误404。

问题不在于ActiveWeb。 这是关于docker。 如何找出,有一些Web应用程序,Jetty喜欢注释类并将在HTTP请求上执行它?

目前我已下载Jetty,它的工作原理。 不幸的是,它没有记录。 当404错误返回时, stdoutstderr没有显示任何内容,并且当前子目录中没有文件出现。

如何在jetty中启用日志记录?

这里的文档http://www.eclipse.org/jetty/documentation/current/configuring-logging.html和http://www.eclipse.org/jetty/documentation/current/configuring-jetty-request-logs.html不清楚和有争议。

例如,第一页说Jetty不使用任何Java登录框架,但也需要一个选择一个。 第二页提供了一些配置示例,但没有说明应放置此代码的位置。

文档是正确的,因为术语“Java日志框架”通常与现代日志框架相关联,如java.util.logging,slf4j,logback,log4j,commons-logging,logkit等。

这是正确的,Jetty不使用任何这些。

Jetty日志记录早于标准化日志记录框架中的所有这些工作。 (Jetty及其日志层创建于1995年)

这就是Jetty日志记录在设置和配置方面的作用(并在文档站点上记录)。

默认行为:

  • 如果您的类路径中存在slf4j ,它将向slf4j发出日志记录事件以使用Slf4jLog处理程序进行处理。
  • 回退到StdErrLog ,发送到System.err。

要配置:

  • 指定要使用的日志记录实现。 选择是:
    • StdErrLog
    • Slf4jLog
    • JavaUtilLog

这可以通过3种不同的方式实现

  1. 使用系统属性设置日志记录impl
 # 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 
  1. 使用jetty-logging.properties从类路径中找到的自发现/配置。

jetty项目本身的例子 :

 # 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 
  1. 使用代码设置Log.setLog(Logger)

这对使用嵌入式docker的人特别有用

 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 oejdpScanningAppProvider - Deployment monitor [file:/Users/joakim/Code/Jetty/distros/jetty-distribution-9.2.1.v20140609/demo-base/webapps/] at interval 1 

这是slf4j – > logback的默认Console appender输出。 这里的整体结构与StdErrLog产生的结构非常不同,所以我现在可以通过Slf4jLog实现告诉jetty正在发射。