Skip to content

Commit 04141de

Browse files
committed
Consistent logging of resolved exceptions
Issue: SPR-17178
1 parent 6027cf2 commit 04141de

File tree

3 files changed

+6
-18
lines changed

3 files changed

+6
-18
lines changed

spring-web/src/main/java/org/springframework/web/server/handler/ResponseStatusExceptionHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ public Mono<Void> handle(ServerWebExchange exchange, Throwable ex) {
7272
if (this.warnLogger != null && this.warnLogger.isWarnEnabled()) {
7373
this.warnLogger.warn(logPrefix + formatError(ex, exchange.getRequest()), ex);
7474
}
75-
else if (logger.isDebugEnabled()) {
76-
logger.debug(logPrefix + formatError(ex, exchange.getRequest()));
75+
else if (logger.isWarnEnabled()) {
76+
logger.warn(logPrefix + formatError(ex, exchange.getRequest()));
7777
}
7878

7979
return exchange.getResponse().setComplete();

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ public ModelAndView resolveException(
136136
ModelAndView result = doResolveException(request, response, handler, ex);
137137
if (result != null) {
138138

139-
// Print debug message, when warn logger is not enabled..
140-
if (logger.isDebugEnabled() && (this.warnLogger == null || !this.warnLogger.isWarnEnabled())) {
141-
logger.debug("Resolved [" + ex + "]" + (result.isEmpty() ? "" : " to " + result));
139+
// Print warn message, when warn logger is not enabled..
140+
if (logger.isWarnEnabled() && (this.warnLogger == null || !this.warnLogger.isWarnEnabled())) {
141+
logger.warn("Resolved [" + ex + "]" + (result.isEmpty() ? "" : " to " + result));
142142
}
143143

144144
// warnLogger with full stack trace (requires explicit config)..

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,6 @@ else if (ex instanceof AsyncRequestTimeoutException) {
252252
protected ModelAndView handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException ex,
253253
HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException {
254254

255-
pageNotFoundLogger.warn(ex.getMessage());
256255
String[] supportedMethods = ex.getSupportedMethods();
257256
if (supportedMethods != null) {
258257
response.setHeader("Allow", StringUtils.arrayToDelimitedString(supportedMethods, ", "));
@@ -376,9 +375,6 @@ protected ModelAndView handleServletRequestBindingException(ServletRequestBindin
376375
protected ModelAndView handleConversionNotSupported(ConversionNotSupportedException ex,
377376
HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException {
378377

379-
if (logger.isWarnEnabled()) {
380-
logger.warn("Failed to convert request element: " + ex);
381-
}
382378
sendServerError(ex, request, response);
383379
return new ModelAndView();
384380
}
@@ -397,9 +393,6 @@ protected ModelAndView handleConversionNotSupported(ConversionNotSupportedExcept
397393
protected ModelAndView handleTypeMismatch(TypeMismatchException ex,
398394
HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException {
399395

400-
if (logger.isWarnEnabled()) {
401-
logger.warn("Failed to bind request element: " + ex);
402-
}
403396
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
404397
return new ModelAndView();
405398
}
@@ -420,9 +413,6 @@ protected ModelAndView handleTypeMismatch(TypeMismatchException ex,
420413
protected ModelAndView handleHttpMessageNotReadable(HttpMessageNotReadableException ex,
421414
HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException {
422415

423-
if (logger.isWarnEnabled()) {
424-
logger.warn("Failed to read HTTP message: " + ex);
425-
}
426416
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
427417
return new ModelAndView();
428418
}
@@ -444,9 +434,6 @@ protected ModelAndView handleHttpMessageNotReadable(HttpMessageNotReadableExcept
444434
protected ModelAndView handleHttpMessageNotWritable(HttpMessageNotWritableException ex,
445435
HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException {
446436

447-
if (logger.isWarnEnabled()) {
448-
logger.warn("Failed to write HTTP message: " + ex);
449-
}
450437
sendServerError(ex, request, response);
451438
return new ModelAndView();
452439
}
@@ -520,6 +507,7 @@ protected ModelAndView handleBindException(BindException ex, HttpServletRequest
520507
protected ModelAndView handleNoHandlerFoundException(NoHandlerFoundException ex,
521508
HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException {
522509

510+
pageNotFoundLogger.warn(ex.getMessage());
523511
response.sendError(HttpServletResponse.SC_NOT_FOUND);
524512
return new ModelAndView();
525513
}

0 commit comments

Comments
 (0)