Disable WARN logging from AbstractHandlerExceptionResolver in Spring
Asked Answered
K

3

6

Below exception handler that is common for all my controllers, is working fine except that I need to disable the WARN log from AbstractHandlerExceptionResolver class after processing the exception. Using Spring Web MVC 5.x version.

@ControllerAdvice
public class AllExceptionHandler{
    @ExceptionHandler(SomeCustomException.class)
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    public void exceptionHandler() {
    }
}

This is the log that is generated which I'm trying to avoid:

02-20-2019 15:22:54,896 WARN [http-nio-8080-exec-1] (AbstractHandlerExceptionResolver.java:140) - Resolved [com.rasa.rrt.ste.controller.SomeCustomException]

I'm not using Spring Boot.

Tried to extend the above AllExceptionHandler class with ExceptionHandlerExceptionResolver and call warnLogCategory(null) in the AllExceptionHandler constructor, but it throws NullPointerException.

Also, I see on Google to set this property spring.mvc.log-resolved-exception=false to disable warning, but not sure where/how to set it.

Keenan answered 23/2, 2019 at 1:35 Comment(3)
Might not be what you are looking for exactly, an alternative option could be: in your logging configuration, you could add an entry for AbstractHandlerExceptionResolver then set the level to DEBUG. Note that it would get rid of all your WARN logs for that class not just the one specific that you don't wantDorita
@lorraine Our application uses log4j2, but Spring uses some other logging I guess, Spring is not taking the log configuration from our log4j2.xml file.Keenan
You can override libraries log level if I'm not wrong, just put an entry on your log config file. We do it for hibernate if when we want to examine its execution by adding entry on our log config file using the hibernate class and specify level.Dorita
L
7

You mentioned spring.mvc.log-resolved-exception=false as a possible solution:

Also, I see on Google to set this property spring.mvc.log-resolved-exception=false to disable warning, but not sure where/how to set it.

The spring.mvc.log-resolved-exception property is a Spring Boot property, and would be set using standard Spring Boot externalized configuration mechanisms. Enabling the property causes Spring Boot to configure HandlerExceptionResolver beans to log exceptions when they otherwise wouldn't.

Whether to enable warn logging of exceptions resolved by a "HandlerExceptionResolver", except for "DefaultHandlerExceptionResolver".

Since you've stated you're not using Spring Boot, this property is not applicable to your scenario.

Laddie answered 8/2, 2021 at 19:6 Comment(0)
C
2

You can disable this warning log in your logback configuration, by specifying in my case in 'logback-spring.groovy' following line

logger("org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver", ERROR)
Crystlecs answered 19/4, 2019 at 10:19 Comment(0)
T
1

When introducing spring-boot-devtools in Spring Boot, the log-resolved-exception will be automatically enabled. To disable it, you need to set spring.mvc.log-resolved-exception: false in the profile file. In the production environment where devtools does not exist, you don’t need to worry about this issue.

Touraco answered 21/9, 2023 at 6:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.