问题描述
我们通过Spring MVC公开了REST服务。我们使用 HandlerExceptionResolver
来记录异常。我们目前记录以下内容:
We have REST services exposed via Spring MVC. We use a HandlerExceptionResolver
to log exceptions. We currently log the following:
- 异常及其堆栈跟踪
- URL
- 请求标题
如果我们还可以记录JSON帖子数据,这将使调试更容易。关于如何获得这个的任何建议?
It would make debugging easier if we could also log the JSON post data as well. Any suggestions on how to get this?
推荐答案
你需要一个过滤器,它可以在读取时保存请求体并提供保存数据到以后的异常记录器。
You need a filter that would save request body when it's being read and provide the saved data to your exception logger later.
Spring包含执行类似的操作。虽然它不直接适合您的问题,但您可以将其用作实现自己的过滤器的参考。
Spring contains AbstractRequestLoggingFilter
that does the similar thing. Though it's not directly suitable for your problem, you can use it as a reference to implement your own filter.
这篇关于如何记录RESTful帖子数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!