【问题标题】:Embedded Jetty org.eclipse.jetty.util.log.StrErrLog not working嵌入式码头 org.eclipse.jetty.util.log.StrErrLog 不工作
【发布时间】:2015-04-28 10:22:01
【问题描述】:

我有一个嵌入式 Jetty,它使用 Jersey Moxy JSON 支持来提供 JSON 合同。它适用于@GET,但不适用于我拥有的@PUT(永远不会被击中)我还在web.xml中配置了跨源过滤器,但它不起作用,比如查看加载的类的一些日志输出那个。

所以我需要记录并已根据此https://www.eclipse.org/jetty/documentation/current/configuring-logging.html 和文档中的以下 2 页实现。

所以我有一个 jetty-logging.properties,它在类路径(在主类的 src/main/path 中)有这个内容,我检查它也在目标目录中。我注意到“ loadProperties("jetty-logging.properties",__props);"以及 org/eclipse/jetty/util/log/Log.java 中的“这是嵌入式模式使用的可选功能”的声明,因此应该被采纳。

org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StrErrLog
org.eclipse.jetty.LEVEL=DEBUG
org.eclipse.jetty.websocket.LEVEL=DEBUG
org.eclipse.jetty.servlet.LEVEL=ALL

我已经按照文档实现了请求日志,并且它在运行时运行,这里是:

    HandlerCollection handlers = new HandlerCollection();
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    RequestLogHandler requestLogHandler = new RequestLogHandler();
    handlers.setHandlers(new Handler[]{contexts,new DefaultHandler(),requestLogHandler});
    server.setHandler(handlers);

    NCSARequestLog requestLog = new NCSARequestLog(locn);
    requestLog.setRetainDays(90);
    requestLog.setAppend(true);
    requestLog.setExtended(false);
    requestLog.setLogTimeZone("GMT");
    requestLogHandler.setRequestLog(requestLog);

我为 locn 变量尝试了相对路径和完整的 Windows 路径(使用 /)。

我尝试设置 Eclipse 调试参数,例如: -Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog -Dorg.eclipse.jetty.servlet.LEVEL=ALL

我在任何时候都没有得到日志文件。我错过了什么?文档当然不涉及嵌入式 Jetty,我已经阅读了很多关于它应该如何工作的不同文章,但没有找到任何可以解决我的问题的东西。

编辑: 我从 mvn 依赖项中注意到:我得到的树输出:

+- org.quartz-scheduler:quartz:jar:2.2.1:compile
 |     \- org.apache.commons:commons-lang3:jar:3.3.2:test
 |  \- org.slf4j:slf4j-api:jar:1.6.6:compile

在控制台中我得到:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

这会扰乱码头对 StdErrLog 的使用吗?

【问题讨论】:

    标签: json logging cross-domain embedded-jetty


    【解决方案1】:

    为了让日志正常工作,我必须意识到 setHandler(Handler) 和 setHandler(Handler[]) 会相互覆盖。我在上面看到的 setupLogging 方法中有前者,而在我的 main 方法中有后者,它在 setupLogging 方法之后运行,因此用我拥有的其他处理程序和过滤器覆盖了 RequestLogHandler。

    【讨论】:

      猜你喜欢
      • 2015-07-11
      • 1970-01-01
      • 1970-01-01
      • 2014-02-25
      • 2019-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多