ApiBoot Logging支持指定单个或者多个路径的前缀进行采集,也就是我们可以指定/user @SpringBootApplication @EnableLoggingClient public class ModifyApibootLoggingCollectionPrefixApplication { public static void main(String[] args) { SpringApplication.run(ModifyApibootLoggingCollectionPrefixApplication.class, args); } } 运行测试
使用idea的Application或者java -jar xxx.jar的形式来运行本章源码,本章源码的端口号配置为8080,我们需要从下面几个点进行测试。
测试点:匹配/user @GetMapping public String welcome(@RequestParam("name") String name) { return "hello, " + name; } }通过如下命令访问测试接口:
➜ ~ curl http://localhost:8080/user?name=hengboy
hello, hengboy
/user路径匹配/user/**表达式,所以我们在控制台可以看到请求日志的打印。
测试点:匹配/order/**路径添加测试控制器类OrderController如下所示:
@RestController
@RequestMapping(value = "/order")
public class OrderController {
@PostMapping
public String submit() {
return "订单:" + UUID.randomUUID().toString() + ",提交成功.";
}
}
通过如下命令访问测试接口:
➜ ~ curl -X POST http://localhost:8080/order
订单:24a24d24-539e-4da9-9272-e68fd592313c,提交成功.
/order路径匹配/order/**表达式,所以我们在控制台也可以看到请求日志的打印。
测试点:其他路径添加测试控制器类OtherController如下所示:
@RestController
public class OtherController {
@GetMapping(value = "/other")
public String other() {
return "this is other path";
}
}
通过如下命令访问测试接口:
➜ ~ curl http://localhost:8080/other
this is other path
由于/other路径并不匹配/user/**或者/order/**表达式,所以我们在控制台并没有看到日志的打印。
敲黑板,划重点ApiBoot Logging支持单个或者多个路径配置来进行过滤指定路径前缀来采集日志,让日志采集不再不可控,更精准的定位到业务请求的日志采集。
本章源码本篇文章示例源码可以通过以下途径获取,目录为SpringBoot2.x/modify-apiboot-logging-collection-prefix:
- Gitee:https://gitee.com/hengboy/spring-boot-chapter
作者个人 博客
使用开源框架 ApiBoot 助你成为Api接口服务架构师



