I need to log more info (method, path and response) when any of my controller returns non 200 HTTP responses but in another separately log. Basically, when a controller returns a 404 (for example), I want it to print just after the controller logs my log like this:
method: GET, path: localhost/product/123, response: 404 NOT_FOUND
I have tried to override logback-spring.xml but didn't get anywhere, tried to create my own EvaluatorFilter still no hope, succeeded with MDC but it will print in every log so this option doesn't help me.
Question: can I do this just by creating a logback-spring.xml file to change the ERROR log type? If yes, can someone give me an example, if not, can it be done in another way?
Any help would be great.