更新时间:2025-03-24 GMT+08:00
method日志
实现原理
devspore-http-log打印methodLog主要是通过Spring的切面来实现的。
添加依赖
pom文件添加如下依赖:
<dependency>
<groupId>com.huaweicloud.devspore</groupId>
<artifactId>devspore-http-log</artifactId>
<version>最新版本</version>
</dependency> 使用方式
在spring的配置文件中添加以下配置,无需改动代码:
devspore:
http-log:
method-level:
#为true时打印methodLog,为false时不打印
enable: true
#此参数控制在哪些方法上打印methodLog,使用aop切面表达式的语法
execution: '(@within(org.springframework.stereotype.Service)'
#需要在methodLog中添加自定义字段时需添加如下配置
custom-fields:
# user:为methodLog中添加的自定义字段名称,x-user为请求头中的key值,devspore-http-log会去请求头中获取该值打印在methodLog中
user: x-user method日志示例
"duration": 199, "logType": "methodLog", "methodName": "getConsumerByRestTemplate", "startTime": "2023-12-28 15:23:44.646", "className": "com.huaweicloud.service.impl.HttpLogServiceImpl", "exceptionClass": "", "serviceName": "httplogtest", "user": "my-custom-field" }
父主题:使用指南

