@@ -53,7 +53,7 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti
5353
5454 private Class <?>[] mappedHandlerClasses ;
5555
56- private Log warnLogger = LogFactory . getLog ( getClass ()) ;
56+ private Log warnLogger ;
5757
5858 private boolean preventResponseCaching = false ;
5959
@@ -96,15 +96,14 @@ public void setMappedHandlerClasses(Class<?>[] mappedHandlerClasses) {
9696 * Set the log category for warn logging. The name will be passed to the underlying logger
9797 * implementation through Commons Logging, getting interpreted as a log category according
9898 * 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.
102101 * @see org.apache.commons.logging.LogFactory#getLog(String)
103102 * @see org.apache.log4j.Logger#getLogger(String)
104103 * @see java.util.logging.Logger#getLogger(String)
105104 */
106105 public void setWarnLogCategory (String loggerName ) {
107- this .warnLogger = ( loggerName != null ? LogFactory .getLog (loggerName ) : null );
106+ this .warnLogger = LogFactory .getLog (loggerName );
108107 }
109108
110109 /**
@@ -128,17 +127,13 @@ public ModelAndView resolveException(HttpServletRequest request, HttpServletResp
128127 Object handler , Exception ex ) {
129128
130129 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.
132131 if (this .logger .isDebugEnabled ()) {
133132 this .logger .debug ("Resolving exception from handler [" + handler + "]: " + ex );
134133 }
134+ logException (ex , request );
135135 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 );
142137 }
143138 else {
144139 return null ;
@@ -176,7 +171,8 @@ protected boolean shouldApplyTo(HttpServletRequest request, Object handler) {
176171 }
177172
178173 /**
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.
180176 * <p>Calls {@link #buildLogMessage} in order to determine the concrete message to log.
181177 * @param ex the exception that got thrown during handler execution
182178 * @param request current HTTP request (useful for obtaining metadata)
@@ -197,8 +193,7 @@ protected void logException(Exception ex, HttpServletRequest request) {
197193 * @return the log message to use
198194 */
199195 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 ;
202197 }
203198
204199 /**
0 commit comments