Improve exception logging in HandlerExceptionResolvers
This commit updates AbstractHandlerExceptionResolver to only log at the WARN level exceptions that are actually resolved by the ExceptionResolver. In case developers wish to log each time an ExceptionResolver is called, a DEBUG level log is still available. Issue: SPR-14392
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,6 +20,7 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.TypeMismatchException;
|
||||
@@ -49,6 +50,11 @@ public class ResponseStatusExceptionResolverTests {
|
||||
|
||||
private final MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
exceptionResolver.setWarnLogCategory(exceptionResolver.getClass().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statusCode() {
|
||||
StatusCodeException ex = new StatusCodeException();
|
||||
|
||||
@@ -80,6 +80,7 @@ public class ExceptionHandlerExceptionResolverTests {
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
this.resolver = new ExceptionHandlerExceptionResolver();
|
||||
this.resolver.setWarnLogCategory(this.resolver.getClass().getName());
|
||||
this.request = new MockHttpServletRequest("GET", "/");
|
||||
this.response = new MockHttpServletResponse();
|
||||
}
|
||||
@@ -399,11 +400,13 @@ public class ExceptionHandlerExceptionResolverTests {
|
||||
@Configuration
|
||||
static class MyConfig {
|
||||
|
||||
@Bean public TestExceptionResolver testExceptionResolver() {
|
||||
@Bean
|
||||
public TestExceptionResolver testExceptionResolver() {
|
||||
return new TestExceptionResolver();
|
||||
}
|
||||
|
||||
@Bean public AnotherTestExceptionResolver anotherTestExceptionResolver() {
|
||||
@Bean
|
||||
public AnotherTestExceptionResolver anotherTestExceptionResolver() {
|
||||
return new AnotherTestExceptionResolver();
|
||||
}
|
||||
}
|
||||
@@ -445,15 +448,18 @@ public class ExceptionHandlerExceptionResolverTests {
|
||||
@Configuration
|
||||
static class MyControllerAdviceConfig {
|
||||
|
||||
@Bean public NotCalledTestExceptionResolver notCalledTestExceptionResolver() {
|
||||
@Bean
|
||||
public NotCalledTestExceptionResolver notCalledTestExceptionResolver() {
|
||||
return new NotCalledTestExceptionResolver();
|
||||
}
|
||||
|
||||
@Bean public BasePackageTestExceptionResolver basePackageTestExceptionResolver() {
|
||||
@Bean
|
||||
public BasePackageTestExceptionResolver basePackageTestExceptionResolver() {
|
||||
return new BasePackageTestExceptionResolver();
|
||||
}
|
||||
|
||||
@Bean public DefaultTestExceptionResolver defaultTestExceptionResolver() {
|
||||
@Bean
|
||||
public DefaultTestExceptionResolver defaultTestExceptionResolver() {
|
||||
return new DefaultTestExceptionResolver();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@ public class DefaultHandlerExceptionResolverTests {
|
||||
@Before
|
||||
public void setUp() {
|
||||
exceptionResolver = new DefaultHandlerExceptionResolver();
|
||||
exceptionResolver.setWarnLogCategory(exceptionResolver.getClass().getName());
|
||||
request = new MockHttpServletRequest();
|
||||
response = new MockHttpServletResponse();
|
||||
request.setMethod("GET");
|
||||
|
||||
Reference in New Issue
Block a user