springboot启动器,自动在日志中打印输入输出参数,快捷方便,无需任何配置项,依赖少,开箱即用。css
无中文乱码,可设置拦截路径和排除路径,可配置是否打印输入和输出。能够用于测试和开发环境排除bug查找问题。也能够直接用于生产环境记录请求。
使用方法:html
1.clone代码到本地git
[AppleScript] 纯文本查看 复制代码
?
1
<font style="color:rgb(61, 70, 77)"><font face="""><font style="font-size:16px">git clone [url=mailto:git@gitee.com]git@gitee.com[/url]:sjlian/printparam-spring-boot-starter.git</font></font></font>
github
2.安装到本地maven库,cd 到项目目录下web
[AppleScript] 纯文本查看 复制代码
?
1
2
<font style="color:rgb(61, 70, 77)"><font face="""><font style="font-size:16px">cd printparam-spring-boot-starter
maven install</font></font></font>
正则表达式
3.引入到springboot项目依赖。spring
[AppleScript] 纯文本查看 复制代码
?
1
2
3
4
5
<font style="color:rgb(61, 70, 77)"><font face="""><font style="font-size:16px"><dependency>
<groupId>com.github.printparam</groupId>
<artifactId>printparam-spring-boot-starter</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency></font></font></font>
json
4.可选,配置参数api
[AppleScript] 纯文本查看 复制代码
?
1
2
3
4
<font style="color:rgb(61, 70, 77)"><font face="""><font style="font-size:16px">print-param.enableInputParam=true 是否在日志中打印输入信息,默认true
print-param.enableOutputResult=false 是否在日志中打印输出信息,默认false
print-param.filterIncludePattern=/ 拦截哪些url进行日志打印 默认/表示所有拦截,正则表达式,建议只拦截接口访问数据如/api/*
print-param.filterExcludePattern=(/webjars/.|/css/.|/images/.|/fonts/.|/js/.*) 正则表达式描述不拦截哪些url打印日志,默认如左</font></font></font>
springboot
5.日志输入格式以下:
[AppleScript] 纯文本查看 复制代码
?
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<font style="color:rgb(61, 70, 77)"><font face="""><font style="font-size:16px" deep="22">对于request:
uri表示请求接口
header表示请求头
form是表单数据
body是json数据
对于response:
return data表示返回数据
request uri:/api/user1/add
request header:{Origin=http://localhost:8081, Accept=/, Connection=keep-alive, User-Agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36, Referer=http://localhost:8081/api/swagger-ui.html, Host=localhost:8081, Accept-Encoding=gzip, deflate, br, Accept-Language=zh-CN,zh;q=0.9, Content-Length=34, Content-Type=application/json}
request form:{}
request body:{ "age": 26, "name": "hello"}
response return data:{"code":0,"message":"success","url":null,"data":{"id":null,"name":"hello","age":26,"version":null}}
request uri:/api/user1/add
request header:{Origin=http://localhost:8081, Accept=/, Connection=keep-alive, User-Agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36, Referer=http://localhost:8081/api/swagger-ui.html, Host=localhost:8081, Accept-Encoding=gzip, deflate, br, Accept-Language=zh-CN,zh;q=0.9, Content-Length=35, Content-Type=application/json}
request form:{}
request body:{ "age": 16, "name": "张三"}
response return data:{"code":0,"message":"success","url":null,"data":{"id":null,"name":"张三","age":16,"version":null}}
request uri:/api/user1/get/1
request header:{Accept=/, Connection=keep-alive, User-Agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36, Referer=http://localhost:8081/api/swagger-ui.html, Host=localhost:8081, Accept-Encoding=gzip, deflate, br, Accept-Language=zh-CN,zh;q=0.9}
request form:{}
request body:
response return data:{"code":0,"message":"success","url":null,"data":null}
request uri:/api/user1/list
request header:{Accept=/, Connection=keep-alive, User-Agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36, Referer=http://localhost:8081/api/swagger-ui.html, Host=localhost:8081, Accept-Encoding=gzip, deflate, br, Accept-Language=zh-CN,zh;q=0.9}
request form:{}
request body:
response return data:{"code":0,"message":"success","url":null,"data":[]}
request uri:/api/demo/getHello
request header:{Accept=/, Connection=keep-alive, User-Agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36, Referer=http://localhost:8081/api/swagger-ui.html, Host=localhost:8081, Accept-Encoding=gzip, deflate, br, Accept-Language=zh-CN,zh;q=0.9}request form:{}request body:response return data:hello</font></font></font>