本文介绍了如何在jetty中启用日志记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在尝试调试我的情况,其中简单的ActiveWeb应用程序未在Jetty下运行。它的行为好像没有任何请求处理类存在并返回错误404. 问题与ActiveWeb无关。这是关于码头。如何找到,有一些Web应用程序,Jetty喜欢注释类并将在HTTP请求上执行它? 目前我已经下载了Jetty并且它有效。不幸的是,它没有记录。 stdout 或 stderr 中没有显示任何内容,日志中没有文件子目录,当404错误返回时。 如何在jetty中启用登录? 文档这里 http://www.eclipse.org/jetty/documentation/current/ configure-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 处理程序。 回退到SErErrLog。 配置: 指定您希望它使用的日志记录实现。 选择: StdErrLog Slf4jLog JavaUtilLog 这可以通过3种不同方式实现 使用系统属性设置日志记录impl #3个不同的选项 -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。属性从类路径中找到自我发现/配置。 来自jetty项目本身的示例: #配置System.err输出 org.eclipse.jetty.util.log .class = org.eclipse.jetty.util.log.StdErrLog #配置StdErrLog将所有jetty命名空间记录为默认值WARN或以上 org.eclipse.jetty.LEVEL = WARN #配置StdErrLog以在DEBUG或以上上记录特定于websocket的命名空间org.eclipse.jetty.websocket.LEVEL = DEBUG 使用代码设置 Log.setLog(记录器) 这是特别的对于那些使用 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:登录初始化@ 378ms 2014 -09-11 10:48:39.067:INFO:oejdp.ScanningAppProvider:main:部署监视器[file:/Users/joakim/Code/Jetty/distros/jetty-distribution-9.2.1.v20140609/demo-base/webapps/ ]在间隔1 请注意,这在输出中没有命名空间声明或严重缩写的命名空间。这告诉我 StdErrLog 正在使用中。 如果正在使用slf4j: 10:50:18.871 [main] INFO org.eclipse.jetty.util.log - 记录初始化@ 352ms 10:50:19.102 [main] INFO oejdpScanningAppProvider - 部署监视器[文件:/Users/joakim/Code/Jetty/distros/jetty-distribution-9.2.1.v20140609/demo-base/webapps/],间隔为1 这是默认值控制台appender 输出 slf4j - > logback 。这里的整体结构与 StdErrLog 产生的结构非常不同,所以我现在可以通过 Slf4jLog 实施。 I am trying to debug my case, where simple ActiveWeb application is not running under Jetty. It behaves as if no any classes for request processing exist and return error 404.The question is not about ActiveWeb. It is about Jetty. How to find out, that having some web application, Jetty has fond annotated class and will execute it on HTTP request?Currently I have downloaded Jetty and it works. Unfortunately, it does no logging. Nothing is displayed in stdout or stderr and no files appear in logs subdirectory at the moment, when 404 error returns.How to enable logging in jetty?Documentation here http://www.eclipse.org/jetty/documentation/current/configuring-logging.html and here http://www.eclipse.org/jetty/documentation/current/configuring-jetty-request-logs.html is not clear and controversal.For example, first page says Jetty does not use any Java loggin framework, but also requires one to select one. The second page provides some example of configuration, but does not say, where this code should be put. 解决方案 The documentation is correct, as the term "Java Logging Framework" is often associated with modern logging frameworks like java.util.logging, slf4j, logback, log4j, commons-logging, logkit, etc.This is correct, Jetty does not use any of those.Jetty logging predates ALL of those efforts at standardized logging frameworks. (Jetty, and its logging layer was created in 1995)This is what Jetty logging does (and is documented at the documentation site) with regards to setup and configuration.Default behavior:If slf4j is present in your classpath, it will emit logging events to slf4j to handle using the Slf4jLog handler.Fallback to StdErrLog, emitting to System.err.To configure:Specify the logging implementation you want it to use.Choices are:StdErrLogSlf4jLogJavaUtilLogThis can be accomplished in 3 different waysUsing a system property to set the logging 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.JavaUtilLogUsing the jetty-logging.properties self discover/configuration found from classpath.Example from jetty project itself:# Configure for System.err outputorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog# Configure StdErrLog to log all jetty namespace at default of WARN or aboveorg.eclipse.jetty.LEVEL=WARN# Configure StdErrLog to log websocket specific namespace at DEBUG or aboveorg.eclipse.jetty.websocket.LEVEL=DEBUGUsing code to set Log.setLog(Logger)This is particularly useful for those using embedded-jetty import org.eclipse.jetty.util.log.Log;import org.eclipse.jetty.util.log.StdErrLog;Log.setLog(new StdErrLog());Advice and Notes:The output of your Jetty server startup will give you hints about the logging implementation it is using.Normal / Default behavior:2014-09-11 10:48:38.726:INFO::main: Logging initialized @378ms2014-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 1Notice that this has either no namespace declaration, or heavily abbreviated namespace in its output. This tells me that the StdErrLog is in use.If slf4j is in use:10:50:18.871 [main] INFO org.eclipse.jetty.util.log - Logging initialized @352ms10: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 1This is a default Console appender output for slf4j -> logback. The overall structure here is very different that what the StdErrLog produces, so I can now tell that jetty is emitting via the Slf4jLog implementation. 这篇关于如何在jetty中启用日志记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-27 15:40