我希望我的 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/