Home > other >  How to log more info on no 200 HTTP responses?
How to log more info on no 200 HTTP responses?

Time:11-03

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.

CodePudding user response:

You could use log4j and specify seperate log files based on the log level as described here, in your case have a seperate file for errors and log your shorter version with warn.

  • Related