java - ReSTLet:所有 500 个错误的日志堆栈跟踪

标签 java logging rest resources restlet

我希望我的 ReSTLet 应用程序记录生成 500 系列 HTTP 错误的任何资源的堆栈跟踪(使用上下文的记录器)。据我所知,这不是默认行为。

换句话说,我不希望我的资源类在represent和acceptRepresentation方法中包含任何记录器代码——它们只是抛出一个ResourceException。我希望在所有资源实例中以集中的方式处理日志记录逻辑。

我可以想到一些黑客方法来做到这一点(例如,从处理日志逻辑的资源子类继承),但看起来这应该内置到框架中。

我错过了什么?

最佳答案

看看StatusService :

Service to handle error statuses. If an exception is thrown within your application or Restlet code, it will be intercepted by this service if it is enabled. When an exception or an error is caught, the getStatus(Throwable, Request, Response) method is first invoked to obtain the status that you want to set on the response. [...]

我上个月才发现这一点,它使我能够真正压缩大量错误处理代码,并确保异常得到处理,并且得到统一处理。

关于java - ReSTLet:所有 500 个错误的日志堆栈跟踪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2090386/

相关文章:

java - 调用之间的 map /收集顺序是否稳定?

c++ - 有一些方法可以使用 g++ C++ 编译器将错误日志打印到外部文件吗? (C++)

c++ - PCAP捕获文件头怎么写?

java - 使用 javax.ws.rs.core.Application 实现通用 JAX-RS Web 服务

java - 如何使用 CMIS REST API 访问 Alfresco 中的文件?

java - 泛化类的方法调用

java - AndroidPlot - 从 GraphWidget 中删除域值

java - 无法创建上限集合 mongodb

java - 使用哪种 Restful Web Services 实现

c++ - 如何在 boost log 2.0 中设置 std::ios_base 标志,如 std::left?