Skip to content

Commit

Permalink
Apply value formatting to resolved exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
rstoyanchev committed Oct 11, 2021
1 parent 38f616a commit 82f8d0d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
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;
Expand Down Expand Up @@ -81,9 +82,10 @@ else if (logger.isDebugEnabled()) {


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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 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.
Expand All @@ -25,6 +25,7 @@
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;
Expand Down Expand Up @@ -142,7 +143,7 @@ public ModelAndView resolveException(
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);
Expand Down Expand Up @@ -207,7 +208,7 @@ protected void logException(Exception ex, HttpServletRequest request) {
* @return the log message to use
*/
protected String buildLogMessage(Exception ex, HttpServletRequest request) {
return "Resolved [" + ex + "]";
return "Resolved [" + LogFormatUtils.formatValue(ex, -1, true) + "]";
}

/**
Expand Down

0 comments on commit 82f8d0d

Please sign in to comment.