Logging REST Exceptions with Spring
To enable logging for REST errors in Spring when using a ResponseEntityExceptionHandler just enable debug on ExceptionHandlerExceptionResolver
Without setting debug to true, your errors will still be handled perfectly but you will not receive any messages in your server logs about the handled error.
Of course, there’s also a complicated way to register an extended ExceptionHandlerExceptionResolver and set the warnLogCategory. But that is too much work when you can just enable debug logging to get a nice message like this:
DEBUG 15 Oct 2014 09:03:58,391 (AbstractHandlerExceptionResolver.java:134) – Resolving exception from handler [null]: org.springframework.web.bind.UnsatisfiedServletRequestParameterException: Parameter conditions “startDay” not met for actual request parameters:
And if you aren’t already using it, you can easily handle any REST exceptions from your Spring Controllers with a @ControllerAdvice annotated class that extends ResponseEntityExceptionHandler. Here is an example RestResponseEntityExceptionHandler that I use:
One thought on “Logging REST Exceptions with Spring”
What is “ExceptionMessage” ? Is this your own class?
Yes, I forgot to remove ExceptionMessage pieces before posting. It is just a simple wrapper class that we used on that project.