Question

We have a service based platform where its possible (/common) for a resource not to be found - e.g. calling our security module with the wrong username will return 404 Not Found, something that will happen every time a user makes a typo in their login box.

We use Spring RestTemplate for these calls, which is great, but every time a 404 is encountered it dutifully logs a warning which is spamming our logs.

We obviously don't want to suppress warnings, except in the specific case of 404 not found but there doesn't appear to be a way to do this (logger is private/final, method to invoke it is private etc).

Our solution is not good - to return 200/OK with empty dataset and handle a null pointer, which is both nasty and not a good restful implementation.

Does anyone know a better way to do this?

Was it helpful?

Solution

How about using a RegexFilter filter on your logging appender?

http://logging.apache.org/log4j/2.x/manual/filters.html#RegexFilter

... that's the Log4J way of doing it, but I'm guessing there must be similar filters for other logging libraries.

OTHER TIPS

Implement a ResponseErrorHandler that returns false for hasError().

Assign it to your rest template using setErrorHandler().

The warning will not be logged.

This was logged in as issue SPR-12760 in the issue tracker of Spring Framework and resolved earlier this year (2015) in version 4.1.6. The solution was twofold: first, the warning message was downgraded to a debug message, and second, it was made easier to override the part of the code that is responsible for handling errors. So as a solution to your problem, upgrade the org.springframework:spring-web module to at least version 4.1.6.RELEASE.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top