乐趣区

关于spring:spring-boot-打印请求到log

将申请打印到 log 的办法很多,参考了上面三个文章,用了最简略的一个办法,应用 spring 中内置的 CommonsRequestLoggingFilter 用来打印 log

新建 bean

@Bean
public CommonsRequestLoggingFilter logFilter() {CommonsRequestLoggingFilter filter = new CommonsRequestLoggingFilter();
 filter.setIncludeQueryString(true);
 filter.setIncludePayload(true);
 filter.setMaxPayloadLength(10000);
 filter.setIncludeHeaders(false);
 filter.setAfterMessagePrefix("REQUEST DATA :");
 return filter;
}

批改 application.properties

logging.level.org.springframework.web.filter.CommonsRequestLoggingFilter=debug

参考
Spring Boot – How to log all requests and responses with exceptions in single place?
Spring – Log Incoming Requests
Logging Requests and Responses in Spring (including body)

退出移动版