Skip to content

Commit e8f6cd1

Browse files
committed
Apply value formatting to resolved exceptions
1 parent 47b8e8d commit e8f6cd1

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

spring-core/src/main/java/org/springframework/core/log/LogFormatUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public abstract class LogFormatUtils {
4343
* @return the formatted value
4444
*/
4545
public static String formatValue(@Nullable Object value, boolean limitLength) {
46-
return formatValue(value, 100, limitLength);
46+
return formatValue(value, (limitLength ? 100 : -1), limitLength);
4747
}
4848

4949
/**

spring-web/src/main/java/org/springframework/web/server/handler/ResponseStatusExceptionHandler.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.apache.commons.logging.LogFactory;
2121
import reactor.core.publisher.Mono;
2222

23+
import org.springframework.core.log.LogFormatUtils;
2324
import org.springframework.http.HttpStatus;
2425
import org.springframework.http.server.reactive.ServerHttpRequest;
2526
import org.springframework.http.server.reactive.ServerHttpResponse;
@@ -81,9 +82,10 @@ else if (logger.isDebugEnabled()) {
8182

8283

8384
private String formatError(Throwable ex, ServerHttpRequest request) {
84-
String reason = ex.getClass().getSimpleName() + ": " + ex.getMessage();
85+
String className = ex.getClass().getSimpleName();
86+
String message = LogFormatUtils.formatValue(ex.getMessage(), -1, true);
8587
String path = request.getURI().getRawPath();
86-
return "Resolved [" + reason + "] for HTTP " + request.getMethod() + " " + path;
88+
return "Resolved [" + className + ": " + message + "] for HTTP " + request.getMethod() + " " + path;
8789
}
8890

8991
private boolean updateResponse(ServerHttpResponse response, Throwable ex) {

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@
2525
import org.apache.commons.logging.LogFactory;
2626

2727
import org.springframework.core.Ordered;
28+
import org.springframework.core.log.LogFormatUtils;
2829
import org.springframework.lang.Nullable;
2930
import org.springframework.util.StringUtils;
3031
import org.springframework.web.servlet.HandlerExceptionResolver;
@@ -142,7 +143,7 @@ public ModelAndView resolveException(
142143
if (result != null) {
143144
// Print debug message when warn logger is not enabled.
144145
if (logger.isDebugEnabled() && (this.warnLogger == null || !this.warnLogger.isWarnEnabled())) {
145-
logger.debug("Resolved [" + ex + "]" + (result.isEmpty() ? "" : " to " + result));
146+
logger.debug(buildLogMessage(ex, request) + (result.isEmpty() ? "" : " to " + result));
146147
}
147148
// Explicitly configured warn logger in logException method.
148149
logException(ex, request);
@@ -215,7 +216,7 @@ protected void logException(Exception ex, HttpServletRequest request) {
215216
* @return the log message to use
216217
*/
217218
protected String buildLogMessage(Exception ex, HttpServletRequest request) {
218-
return "Resolved [" + ex + "]";
219+
return "Resolved [" + LogFormatUtils.formatValue(ex, -1, true) + "]";
219220
}
220221

221222
/**

0 commit comments

Comments
 (0)