As a user I would like to be able to easily log any ErrorResponse that is returned as response to a web request. This logging allows me to monitor which specific problems are returned and allows easier troubleshooting.

It should not matter where the ErrorResponse comes from, for instance thrown directly from a controller method, returned in an @ExceptionHandler (as a ErrorResponse or ProblemDetail), created by the ResponseEntityExceptionHandler, or any other way.

I would like to be able to filter which types of problems are logged. For instance, certain input validation problems are probably not interesting to log. Therefor a facility should be provided that allows me to configure which problems should be logged, and which shouldn’t. Preferably I should be able to use Spring environment properties to turn logging on for problems of a specific type (using the type field?)

I can imagine that not everybody wants to log ErrorResponse instances in the same way, for instance some might want different information in the log message or would prefer a specific log marker to be used. Therefor I propose that the code that does the actual logging can easily be replaced by custom logging logic.

Some default logging should be provided, and I suggest that the following ProblemDetail fields are in the log message: type, title, detail and status.

Note: I have discussed this feature request with @rstoyanchev at Spring I/O 2023

Comment From: rstoyanchev

That'll be a good feature indeed. We'll explore some options to support it.

Comment From: rstoyanchev

This is a bit more involved, so it will go into 6.2. I've created PR #31822 with the proposed changes. We don't have 6.2 snapshots yet, but as soon as we do I will set the target milestone on the PR and comment.

Comment From: mzeijen

Fair enough. And good idea regarding the interception system, as we can build our logging solution on top of it.

Thanks for not forgetting about this.