diff --git a/spring-core/src/main/java/org/springframework/core/log/LogFormatUtils.java b/spring-core/src/main/java/org/springframework/core/log/LogFormatUtils.java index cbcd63bf6f..8ef04c71ba 100644 --- a/spring-core/src/main/java/org/springframework/core/log/LogFormatUtils.java +++ b/spring-core/src/main/java/org/springframework/core/log/LogFormatUtils.java @@ -43,7 +43,7 @@ public abstract class LogFormatUtils { * @return the formatted value */ public static String formatValue(@Nullable Object value, boolean limitLength) { - return formatValue(value, 100, limitLength); + return formatValue(value, (limitLength ? 100 : -1), limitLength); } /** diff --git a/spring-web/src/main/java/org/springframework/web/server/handler/ResponseStatusExceptionHandler.java b/spring-web/src/main/java/org/springframework/web/server/handler/ResponseStatusExceptionHandler.java index 618200530e..47ae9ce358 100644 --- a/spring-web/src/main/java/org/springframework/web/server/handler/ResponseStatusExceptionHandler.java +++ b/spring-web/src/main/java/org/springframework/web/server/handler/ResponseStatusExceptionHandler.java @@ -20,6 +20,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import reactor.core.publisher.Mono; +import org.springframework.core.log.LogFormatUtils; import org.springframework.http.HttpStatus; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpResponse; @@ -81,9 +82,10 @@ public class ResponseStatusExceptionHandler implements WebExceptionHandler { private String formatError(Throwable ex, ServerHttpRequest request) { - String reason = ex.getClass().getSimpleName() + ": " + ex.getMessage(); + String className = ex.getClass().getSimpleName(); + String message = LogFormatUtils.formatValue(ex.getMessage(), -1, true); String path = request.getURI().getRawPath(); - return "Resolved [" + reason + "] for HTTP " + request.getMethod() + " " + path; + return "Resolved [" + className + ": " + message + "] for HTTP " + request.getMethod() + " " + path; } private boolean updateResponse(ServerHttpResponse response, Throwable ex) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerExceptionResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerExceptionResolver.java index e5e2db0b6a..e96c43987a 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerExceptionResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerExceptionResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.core.Ordered; +import org.springframework.core.log.LogFormatUtils; import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import org.springframework.web.servlet.HandlerExceptionResolver; @@ -142,7 +143,7 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti if (result != null) { // Print debug message when warn logger is not enabled. if (logger.isDebugEnabled() && (this.warnLogger == null || !this.warnLogger.isWarnEnabled())) { - logger.debug("Resolved [" + ex + "]" + (result.isEmpty() ? "" : " to " + result)); + logger.debug(buildLogMessage(ex, request) + (result.isEmpty() ? "" : " to " + result)); } // Explicitly configured warn logger in logException method. logException(ex, request); @@ -215,7 +216,7 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti * @return the log message to use */ protected String buildLogMessage(Exception ex, HttpServletRequest request) { - return "Resolved [" + ex + "]"; + return "Resolved [" + LogFormatUtils.formatValue(ex, -1, true) + "]"; } /**