【问题标题】:Olingo v4 + log4j2Olingo v4 + log4j2
【发布时间】:2020-08-12 17:04:01
【问题描述】:

我找不到任何关于 Olingo v4 系统日志的信息,比如 spring boot。 教程包含slf4j,所以framework里面必须有内部日志

   <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-simple</artifactId>
      <version>${slf4j.version}</version>
      <scope>runtime</scope>
    </dependency>

但我无法在教程或示例代码中找到任何日志配置。 我想使用 log4j2 进行日志记录,我希望在 web.xml 中使用特定参数,就像它在 spring boot 中一样工作

<context-param>
    <param-name>log4jConfiguration</param-name>
    <param-value>log4j2.properties</param-value>
</context-param>

此外,我找到了 v2 的 ODataDebugCallback 实现 - Debug Support and Error Handling

但它适用于 v2,不适用于 v4

是否有任何上下文参数可供使用或类似于 ODataDebugCallback 的东西用于日志记录?

小案例说明。

我在数据库之上创建了 Olingo v4 OData API。其中一个关键特性是动态元数据构建。它最初工作得很好,但是当我创建新表时,我得到了

{
    "error": {
        "code": null,
        "message": "OData Library: An exception without message text was thrown."
    }
}

OData servlet 中没有任何问题

        try {
            /*session, storage, handler, edm providers init here*/

            // let the handler do the work
            handler.process(req, resp);
        } catch (Exception e) {
            log.error("Server Error occurred in ODataServlet", e); //app is not getting here
            throw new ServletException(e);
        } finally {
            log.debug("========== Request end ==========");
        }

还有我的日志

[DEBUG] ODataServlet - ========== Request begin ==========
[DEBUG] ODataServlet - Received GET request /myOdataServer.svc/$metadata from 0:0:0:0:0:0:0:1
[DEBUG] JDBCFactory - Opening connection to jdbc:postgresql://host/card_storage
[DEBUG] ODataServlet - ========== Request end ==========

我希望从框架中获得更多关于错误的信息:堆栈跟踪、行号等。

【问题讨论】:

    标签: java odata olingo


    【解决方案1】:

    要获取异常跟踪,您可以检查 ServerCoreDebugger 类。

    基本上,您需要将 DebugSupport 注册到 ODataHttpHandler,并将“odata-debug=json”之类的查询参数添加到您的请求 url 以使用 DefaultDebugSupport 从响应中获取异常跟踪。

    handler.register(new DefaultDebugSupport());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-14
      • 2022-10-18
      • 1970-01-01
      • 2017-10-21
      • 2016-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多