SpringBoot 日志显示(truncate...),输出完整日志
本文地址:https://www.cnblogs.com/hchengmx/p/18119562
在查看SpringBoot查看日志中,http的response body会显示不全,如下:
2024-04-07 09:39:53.758|172.17.0.8|DEBUG|[qtp1763344271-7365]|org.springframework.core.log.LogFormatUtils.traceDebug(LogFormatUtils.java:119)|Writing [BaseResponseDTO(requestId=null, responseDateTime=Sun Apr 07 09:39:53 CST 2024, responseStatus=SUCCES (truncated)...]
原因是由于Spring Boot在输出日志的方法里面,当为Debug级别日志时,默认限制了最大输出为100。
public static String formatValue(@Nullable Object value, boolean limitLength) {
return formatValue(value, (limitLength ? 100 : -1), limitLength);
}
The logging of encoded and decoded values, for both Spring MVC and WebFlux, now logs the full value at TRACE, and up to 100 chars at DEBUG. However I'm keeping the ticket open because I had to introduce quite a bit of duplication and we need to find a better solution.
解决方案:添加上这行配置,使得responsebody 的日志级别为 TRACE
logging.level.org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor=TRACE