Consistent logging of resolved exceptions

Issue: SPR-17178
This commit is contained in:
Rossen Stoyanchev 2018-08-15 10:57:51 +03:00
parent 6027cf2255
commit 04141dee65
3 changed files with 6 additions and 18 deletions

View File

@ -72,8 +72,8 @@ public class ResponseStatusExceptionHandler implements WebExceptionHandler {
if (this.warnLogger != null && this.warnLogger.isWarnEnabled()) { if (this.warnLogger != null && this.warnLogger.isWarnEnabled()) {
this.warnLogger.warn(logPrefix + formatError(ex, exchange.getRequest()), ex); this.warnLogger.warn(logPrefix + formatError(ex, exchange.getRequest()), ex);
} }
else if (logger.isDebugEnabled()) { else if (logger.isWarnEnabled()) {
logger.debug(logPrefix + formatError(ex, exchange.getRequest())); logger.warn(logPrefix + formatError(ex, exchange.getRequest()));
} }
return exchange.getResponse().setComplete(); return exchange.getResponse().setComplete();

View File

@ -136,9 +136,9 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti
ModelAndView result = doResolveException(request, response, handler, ex); ModelAndView result = doResolveException(request, response, handler, ex);
if (result != null) { if (result != null) {
// Print debug message, when warn logger is not enabled.. // Print warn message, when warn logger is not enabled..
if (logger.isDebugEnabled() && (this.warnLogger == null || !this.warnLogger.isWarnEnabled())) { if (logger.isWarnEnabled() && (this.warnLogger == null || !this.warnLogger.isWarnEnabled())) {
logger.debug("Resolved [" + ex + "]" + (result.isEmpty() ? "" : " to " + result)); logger.warn("Resolved [" + ex + "]" + (result.isEmpty() ? "" : " to " + result));
} }
// warnLogger with full stack trace (requires explicit config).. // warnLogger with full stack trace (requires explicit config)..

View File

@ -252,7 +252,6 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes
protected ModelAndView handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException ex, protected ModelAndView handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException ex,
HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException {
pageNotFoundLogger.warn(ex.getMessage());
String[] supportedMethods = ex.getSupportedMethods(); String[] supportedMethods = ex.getSupportedMethods();
if (supportedMethods != null) { if (supportedMethods != null) {
response.setHeader("Allow", StringUtils.arrayToDelimitedString(supportedMethods, ", ")); response.setHeader("Allow", StringUtils.arrayToDelimitedString(supportedMethods, ", "));
@ -376,9 +375,6 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes
protected ModelAndView handleConversionNotSupported(ConversionNotSupportedException ex, protected ModelAndView handleConversionNotSupported(ConversionNotSupportedException ex,
HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException {
if (logger.isWarnEnabled()) {
logger.warn("Failed to convert request element: " + ex);
}
sendServerError(ex, request, response); sendServerError(ex, request, response);
return new ModelAndView(); return new ModelAndView();
} }
@ -397,9 +393,6 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes
protected ModelAndView handleTypeMismatch(TypeMismatchException ex, protected ModelAndView handleTypeMismatch(TypeMismatchException ex,
HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { 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); response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return new ModelAndView(); return new ModelAndView();
} }
@ -420,9 +413,6 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes
protected ModelAndView handleHttpMessageNotReadable(HttpMessageNotReadableException ex, protected ModelAndView handleHttpMessageNotReadable(HttpMessageNotReadableException ex,
HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { 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); response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return new ModelAndView(); return new ModelAndView();
} }
@ -444,9 +434,6 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes
protected ModelAndView handleHttpMessageNotWritable(HttpMessageNotWritableException ex, protected ModelAndView handleHttpMessageNotWritable(HttpMessageNotWritableException ex,
HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException {
if (logger.isWarnEnabled()) {
logger.warn("Failed to write HTTP message: " + ex);
}
sendServerError(ex, request, response); sendServerError(ex, request, response);
return new ModelAndView(); return new ModelAndView();
} }
@ -520,6 +507,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes
protected ModelAndView handleNoHandlerFoundException(NoHandlerFoundException ex, protected ModelAndView handleNoHandlerFoundException(NoHandlerFoundException ex,
HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException {
pageNotFoundLogger.warn(ex.getMessage());
response.sendError(HttpServletResponse.SC_NOT_FOUND); response.sendError(HttpServletResponse.SC_NOT_FOUND);
return new ModelAndView(); return new ModelAndView();
} }