@@ -53,7 +53,7 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti
53
53
54
54
private Class <?>[] mappedHandlerClasses ;
55
55
56
- private Log warnLogger = LogFactory . getLog ( getClass ()) ;
56
+ private Log warnLogger ;
57
57
58
58
private boolean preventResponseCaching = false ;
59
59
@@ -96,15 +96,14 @@ public void setMappedHandlerClasses(Class<?>[] mappedHandlerClasses) {
96
96
* Set the log category for warn logging. The name will be passed to the underlying logger
97
97
* implementation through Commons Logging, getting interpreted as a log category according
98
98
* to the logger's configuration.
99
- * <p>Default is warn logging using the {@link AbstractHandlerExceptionResolver} class name derived logger.
100
- * <p>Set to {@code null} to disable warn logging.
101
- * <p>Override the {@link #logException} method for custom logging.
99
+ * <p>Default is no warn logging. Specify this setting to activate warn logging into a specific
100
+ * category. Alternatively, override the {@link #logException} method for custom logging.
102
101
* @see org.apache.commons.logging.LogFactory#getLog(String)
103
102
* @see org.apache.log4j.Logger#getLogger(String)
104
103
* @see java.util.logging.Logger#getLogger(String)
105
104
*/
106
105
public void setWarnLogCategory (String loggerName ) {
107
- this .warnLogger = ( loggerName != null ? LogFactory .getLog (loggerName ) : null );
106
+ this .warnLogger = LogFactory .getLog (loggerName );
108
107
}
109
108
110
109
/**
@@ -128,17 +127,13 @@ public ModelAndView resolveException(HttpServletRequest request, HttpServletResp
128
127
Object handler , Exception ex ) {
129
128
130
129
if (shouldApplyTo (request , handler )) {
131
- // Log exception at debug log level
130
+ // Log exception, both at debug log level and at warn level, if desired.
132
131
if (this .logger .isDebugEnabled ()) {
133
132
this .logger .debug ("Resolving exception from handler [" + handler + "]: " + ex );
134
133
}
134
+ logException (ex , request );
135
135
prepareResponse (ex , response );
136
- ModelAndView mav = doResolveException (request , response , handler , ex );
137
- if (mav != null ) {
138
- // Log exception message at warn log level
139
- logException (ex , request );
140
- }
141
- return mav ;
136
+ return doResolveException (request , response , handler , ex );
142
137
}
143
138
else {
144
139
return null ;
@@ -176,7 +171,8 @@ protected boolean shouldApplyTo(HttpServletRequest request, Object handler) {
176
171
}
177
172
178
173
/**
179
- * Log the given exception message at warn level.
174
+ * Log the given exception at warn level, provided that warn logging has been
175
+ * activated through the {@link #setWarnLogCategory "warnLogCategory"} property.
180
176
* <p>Calls {@link #buildLogMessage} in order to determine the concrete message to log.
181
177
* @param ex the exception that got thrown during handler execution
182
178
* @param request current HTTP request (useful for obtaining metadata)
@@ -197,8 +193,7 @@ protected void logException(Exception ex, HttpServletRequest request) {
197
193
* @return the log message to use
198
194
*/
199
195
protected String buildLogMessage (Exception ex , HttpServletRequest request ) {
200
- String message = (ex != null ? ex .getMessage () : "null" );
201
- return "Handler execution resulted in exception: " + (message != null ? message : "null" );
196
+ return "Handler execution resulted in exception: " + ex ;
202
197
}
203
198
204
199
/**
0 commit comments