Tom Norton Tom Norton - 2 years ago 94
Java Question

How can I log RESTful post data?

We have REST services exposed via Spring MVC. We use a

to log exceptions. We currently log the following:

  • The exception and its stack trace

  • The URL

  • The request headers

It would make debugging easier if we could also log the JSON post data as well. Any suggestions on how to get this?

Answer Source

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 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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download