Consistent logging of resolved exceptions
Issue: SPR-17178
This commit is contained in:
@@ -132,12 +132,16 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti
|
||||
HttpServletRequest request, HttpServletResponse response, @Nullable Object handler, Exception ex) {
|
||||
|
||||
if (shouldApplyTo(request, handler)) {
|
||||
if (this.logger.isDebugEnabled()) {
|
||||
this.logger.debug("Resolving exception from handler [" + handler + "]: " + ex);
|
||||
}
|
||||
prepareResponse(ex, response);
|
||||
ModelAndView result = doResolveException(request, response, handler, ex);
|
||||
if (result != null) {
|
||||
|
||||
// Print warn message, when warn logger is not enabled..
|
||||
if (logger.isWarnEnabled() && (this.warnLogger == null || !this.warnLogger.isWarnEnabled())) {
|
||||
logger.warn("Resolved [" + ex + "]" + (result.isEmpty() ? "" : " to " + result));
|
||||
}
|
||||
|
||||
// warnLogger with full stack trace (requires explicit config)..
|
||||
logException(ex, request);
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -252,7 +252,6 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes
|
||||
protected ModelAndView handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException ex,
|
||||
HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException {
|
||||
|
||||
pageNotFoundLogger.warn(ex.getMessage());
|
||||
String[] supportedMethods = ex.getSupportedMethods();
|
||||
if (supportedMethods != null) {
|
||||
response.setHeader("Allow", StringUtils.arrayToDelimitedString(supportedMethods, ", "));
|
||||
@@ -376,9 +375,6 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes
|
||||
protected ModelAndView handleConversionNotSupported(ConversionNotSupportedException ex,
|
||||
HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException {
|
||||
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Failed to convert request element: " + ex);
|
||||
}
|
||||
sendServerError(ex, request, response);
|
||||
return new ModelAndView();
|
||||
}
|
||||
@@ -397,9 +393,6 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes
|
||||
protected ModelAndView handleTypeMismatch(TypeMismatchException ex,
|
||||
HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException {
|
||||
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Failed to bind request element: " + ex);
|
||||
}
|
||||
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
|
||||
return new ModelAndView();
|
||||
}
|
||||
@@ -420,9 +413,6 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes
|
||||
protected ModelAndView handleHttpMessageNotReadable(HttpMessageNotReadableException ex,
|
||||
HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException {
|
||||
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Failed to read HTTP message: " + ex);
|
||||
}
|
||||
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
|
||||
return new ModelAndView();
|
||||
}
|
||||
@@ -444,9 +434,6 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes
|
||||
protected ModelAndView handleHttpMessageNotWritable(HttpMessageNotWritableException ex,
|
||||
HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException {
|
||||
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Failed to write HTTP message: " + ex);
|
||||
}
|
||||
sendServerError(ex, request, response);
|
||||
return new ModelAndView();
|
||||
}
|
||||
@@ -520,6 +507,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes
|
||||
protected ModelAndView handleNoHandlerFoundException(NoHandlerFoundException ex,
|
||||
HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException {
|
||||
|
||||
pageNotFoundLogger.warn(ex.getMessage());
|
||||
response.sendError(HttpServletResponse.SC_NOT_FOUND);
|
||||
return new ModelAndView();
|
||||
}
|
||||
@@ -542,8 +530,8 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes
|
||||
if (!response.isCommitted()) {
|
||||
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
|
||||
}
|
||||
else if (logger.isDebugEnabled()) {
|
||||
logger.debug("Async timeout for " + request.getMethod() + " [" + request.getRequestURI() + "]");
|
||||
else {
|
||||
logger.warn("Async request timed out");
|
||||
}
|
||||
return new ModelAndView();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user