随笔 - 49  文章 - 0  评论 - 20  阅读 - 12万

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

参考资料

  1. logging - How to show complete log messages on Spring-boot - Stack Overflow
  2. Common Application Properties
  3. Truncate large response bodies when logging in RequestResponseBodyMethodProcessor [SPR-17254] · Issue #21787 · spring-projects/spring-framework · GitHub
posted on   hchengmx  阅读(340)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· 单线程的Redis速度为什么快?
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示