Skip to content

Commit 1621125

Browse files
committed
@ExceptionHandler methods logs at DEBUG level again
Issue: SPR-17383
1 parent a0b42a3 commit 1621125

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,18 @@ public ModelAndView resolveException(
135135
prepareResponse(ex, response);
136136
ModelAndView result = doResolveException(request, response, handler, ex);
137137
if (result != null) {
138-
// Print warn message when warn logger is not enabled...
139-
if (logger.isWarnEnabled() && (this.warnLogger == null || !this.warnLogger.isWarnEnabled())) {
140-
logger.warn("Resolved [" + ex + "]" + (result.isEmpty() ? "" : " to " + result));
138+
// Print warn or debug message when warn logger is not enabled...
139+
if (this.warnLogger == null || !this.warnLogger.isWarnEnabled()) {
140+
if (!useWarnLevelWhenWarnLoggerNotEnabled()) {
141+
if (logger.isDebugEnabled()) {
142+
logger.debug("Resolved [" + ex + "]" + (result.isEmpty() ? "" : " to " + result));
143+
}
144+
}
145+
else if (logger.isWarnEnabled()) {
146+
logger.warn("Resolved [" + ex + "]" + (result.isEmpty() ? "" : " to " + result));
147+
}
141148
}
142-
// warnLogger with full stack trace (requires explicit config)
149+
// Log with warnLogger (requires explicit config)
143150
logException(ex, request);
144151
}
145152
return result;
@@ -179,6 +186,16 @@ protected boolean shouldApplyTo(HttpServletRequest request, @Nullable Object han
179186
return (this.mappedHandlers == null && this.mappedHandlerClasses == null);
180187
}
181188

189+
/**
190+
* Whether to log warn level messages (return value "true") or debug level
191+
* messages (return value "false") through the regular class logger when
192+
* {@link #setWarnLogCategory warn logging} is not activated.
193+
* <p>By default returns "true".
194+
*/
195+
protected boolean useWarnLevelWhenWarnLoggerNotEnabled() {
196+
return true;
197+
}
198+
182199
/**
183200
* Log the given exception at warn level, provided that warn logging has been
184201
* activated through the {@link #setWarnLogCategory "warnLogCategory"} property.

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolver.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,4 +491,10 @@ protected ServletInvocableHandlerMethod getExceptionHandlerMethod(
491491
return null;
492492
}
493493

494+
@Override
495+
protected boolean useWarnLevelWhenWarnLoggerNotEnabled() {
496+
// Use DEBUG level
497+
return false;
498+
}
499+
494500
}

0 commit comments

Comments
 (0)