将请求打印到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)
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。