Skip to content

Commit a409233

Browse files
committed
Consistent logging of resolved exceptions
Issue: SPR-17178
1 parent 7a97ba5 commit a409233

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerExceptionResolver.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,16 @@ public ModelAndView resolveException(
128128
HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
129129

130130
if (shouldApplyTo(request, handler)) {
131-
if (this.logger.isDebugEnabled()) {
132-
this.logger.debug("Resolving exception from handler [" + handler + "]: " + ex);
133-
}
134131
prepareResponse(ex, response);
135132
ModelAndView result = doResolveException(request, response, handler, ex);
136133
if (result != null) {
134+
135+
// Print warn message, when warn logger is not enabled..
136+
if (logger.isWarnEnabled() && (this.warnLogger == null || !this.warnLogger.isWarnEnabled())) {
137+
logger.warn("Resolved [" + ex + "]" + (result.isEmpty() ? "" : " to " + result));
138+
}
139+
140+
// warnLogger with full stack trace (requires explicit config)..
137141
logException(ex, request);
138142
}
139143
return result;

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolver.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ protected ModelAndView handleNoSuchRequestHandlingMethod(org.springframework.web
218218
protected ModelAndView handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException ex,
219219
HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException {
220220

221-
pageNotFoundLogger.warn(ex.getMessage());
222221
String[] supportedMethods = ex.getSupportedMethods();
223222
if (supportedMethods != null) {
224223
response.setHeader("Allow", StringUtils.arrayToDelimitedString(supportedMethods, ", "));
@@ -342,9 +341,6 @@ protected ModelAndView handleServletRequestBindingException(ServletRequestBindin
342341
protected ModelAndView handleConversionNotSupported(ConversionNotSupportedException ex,
343342
HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException {
344343

345-
if (logger.isWarnEnabled()) {
346-
logger.warn("Failed to convert request element: " + ex);
347-
}
348344
sendServerError(ex, request, response);
349345
return new ModelAndView();
350346
}
@@ -363,9 +359,6 @@ protected ModelAndView handleConversionNotSupported(ConversionNotSupportedExcept
363359
protected ModelAndView handleTypeMismatch(TypeMismatchException ex,
364360
HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException {
365361

366-
if (logger.isWarnEnabled()) {
367-
logger.warn("Failed to bind request element: " + ex);
368-
}
369362
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
370363
return new ModelAndView();
371364
}
@@ -386,9 +379,6 @@ protected ModelAndView handleTypeMismatch(TypeMismatchException ex,
386379
protected ModelAndView handleHttpMessageNotReadable(HttpMessageNotReadableException ex,
387380
HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException {
388381

389-
if (logger.isWarnEnabled()) {
390-
logger.warn("Failed to read HTTP message: " + ex);
391-
}
392382
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
393383
return new ModelAndView();
394384
}
@@ -410,9 +400,6 @@ protected ModelAndView handleHttpMessageNotReadable(HttpMessageNotReadableExcept
410400
protected ModelAndView handleHttpMessageNotWritable(HttpMessageNotWritableException ex,
411401
HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException {
412402

413-
if (logger.isWarnEnabled()) {
414-
logger.warn("Failed to write HTTP message: " + ex);
415-
}
416403
sendServerError(ex, request, response);
417404
return new ModelAndView();
418405
}
@@ -508,8 +495,8 @@ protected ModelAndView handleAsyncRequestTimeoutException(AsyncRequestTimeoutExc
508495
if (!response.isCommitted()) {
509496
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
510497
}
511-
else if (logger.isDebugEnabled()) {
512-
logger.debug("Async timeout for " + request.getMethod() + " [" + request.getRequestURI() + "]");
498+
else {
499+
logger.warn("Async request timed out");
513500
}
514501
return new ModelAndView();
515502
}

0 commit comments

Comments
 (0)