Sleuth实现日志采样
阅读 (9485393)
分享
1、用Sleuth实现日志采样
1.1、在服务消费者添加依赖
<!--Sleuth的依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
<version>1.1.3.RELEASE</version>
</dependency>
1.2、添加配置
#设置抽样采集率100%
spring.sleuth.sampler.probability=1
#设置日志级别为debug
logging.level.org.springframework.cloud.sleuth=debug
1.3、修改测试接口
//获取Logger对象
private static Logger logger= LoggerFactory.getLogger(HelloController.class);
@GetMapping("/hello")
public String hello(@RequestParam(value = "name",required = false) String name){
if (StringUtils.isEmpty(name)){
name=this.name;
}
logger.info("获得了请求");
return name;
}
1.4、测试
步骤:
1、启动服务中心
2、启动服务提供者
3、启动服务消费者
4、访问:http://localhost:50006/hello
控制台输出:INFO [consumer1,cc9dea43a9cb8a97,cc9dea43a9cb8a97,false] 1215 — [io-50012-exec-2]
需要
登录
才可以提问哦
: