共计 646 个字符,预计需要花费 2 分钟才能阅读完成。
将申请打印到 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)
正文完