Skip to content

Commit

Permalink
Revert most SPR-13100 changes since SPR-13267 was a better fix
Browse files Browse the repository at this point in the history
Issue: SPR-13596
  • Loading branch information
sdeleuze committed Nov 2, 2015
1 parent 62cd6ad commit 76d7f45
Showing 1 changed file with 10 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti

private Class<?>[] mappedHandlerClasses;

private Log warnLogger = LogFactory.getLog(getClass());
private Log warnLogger;

private boolean preventResponseCaching = false;

Expand Down Expand Up @@ -96,15 +96,14 @@ public void setMappedHandlerClasses(Class<?>[] mappedHandlerClasses) {
* Set the log category for warn logging. The name will be passed to the underlying logger
* implementation through Commons Logging, getting interpreted as a log category according
* to the logger's configuration.
* <p>Default is warn logging using the {@link AbstractHandlerExceptionResolver} class name derived logger.
* <p>Set to {@code null} to disable warn logging.
* <p>Override the {@link #logException} method for custom logging.
* <p>Default is no warn logging. Specify this setting to activate warn logging into a specific
* category. Alternatively, override the {@link #logException} method for custom logging.
* @see org.apache.commons.logging.LogFactory#getLog(String)
* @see org.apache.log4j.Logger#getLogger(String)
* @see java.util.logging.Logger#getLogger(String)
*/
public void setWarnLogCategory(String loggerName) {
this.warnLogger = (loggerName != null ? LogFactory.getLog(loggerName) : null);
this.warnLogger = LogFactory.getLog(loggerName);
}

/**
Expand All @@ -128,17 +127,13 @@ public ModelAndView resolveException(HttpServletRequest request, HttpServletResp
Object handler, Exception ex) {

if (shouldApplyTo(request, handler)) {
// Log exception at debug log level
// Log exception, both at debug log level and at warn level, if desired.
if (this.logger.isDebugEnabled()) {
this.logger.debug("Resolving exception from handler [" + handler + "]: " + ex);
}
logException(ex, request);
prepareResponse(ex, response);
ModelAndView mav = doResolveException(request, response, handler, ex);
if (mav != null) {
// Log exception message at warn log level
logException(ex, request);
}
return mav;
return doResolveException(request, response, handler, ex);
}
else {
return null;
Expand Down Expand Up @@ -176,7 +171,8 @@ protected boolean shouldApplyTo(HttpServletRequest request, Object handler) {
}

/**
* Log the given exception message at warn level.
* Log the given exception at warn level, provided that warn logging has been
* activated through the {@link #setWarnLogCategory "warnLogCategory"} property.
* <p>Calls {@link #buildLogMessage} in order to determine the concrete message to log.
* @param ex the exception that got thrown during handler execution
* @param request current HTTP request (useful for obtaining metadata)
Expand All @@ -197,8 +193,7 @@ protected void logException(Exception ex, HttpServletRequest request) {
* @return the log message to use
*/
protected String buildLogMessage(Exception ex, HttpServletRequest request) {
String message = (ex != null ? ex.getMessage() : "null");
return "Handler execution resulted in exception: " + (message != null ? message : "null");
return "Handler execution resulted in exception: " + ex;
}

/**
Expand Down

0 comments on commit 76d7f45

Please sign in to comment.