refactor(log): 优化日志处理器解析 description、module 方法

This commit is contained in:
2025-01-02 20:33:33 +08:00
parent eb2cac54f7
commit a6c9d33024
5 changed files with 25 additions and 60 deletions

View File

@@ -13,12 +13,6 @@
<description>ContiNew Starter 日志模块 - 基于拦截器实现Spring Boot Actuator HttpTrace 增强版)</description>
<dependencies>
<!-- Swagger 注解 -->
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations-jakarta</artifactId>
</dependency>
<!-- TTL线程间传递 ThreadLocal异步执行时上下文传递的解决方案 -->
<dependency>
<groupId>com.alibaba</groupId>

View File

@@ -16,14 +16,7 @@
package top.continew.starter.log.handler;
import cn.hutool.core.annotation.AnnotationUtil;
import cn.hutool.core.text.CharSequenceUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import top.continew.starter.log.AbstractLogHandler;
import top.continew.starter.log.model.LogRecord;
import java.lang.reflect.Method;
/**
* 日志处理器-拦截器版实现
@@ -32,31 +25,4 @@ import java.lang.reflect.Method;
* @since 2.8.0
*/
public class InterceptorLogHandler extends AbstractLogHandler {
@Override
public void logDescription(LogRecord logRecord, Method targetMethod) {
super.logDescription(logRecord, targetMethod);
if (CharSequenceUtil.isNotBlank(logRecord.getDescription())) {
return;
}
// 例如:@Operation(summary="新增部门") -> 新增部门
Operation methodOperation = AnnotationUtil.getAnnotation(targetMethod, Operation.class);
if (null != methodOperation) {
logRecord.setDescription(CharSequenceUtil.blankToDefault(methodOperation.summary(), "请在该接口方法上指定日志描述"));
}
}
@Override
public void logModule(LogRecord logRecord, Method targetMethod, Class<?> targetClass) {
super.logModule(logRecord, targetMethod, targetClass);
if (CharSequenceUtil.isNotBlank(logRecord.getModule())) {
return;
}
// 例如:@Tag(name = "部门管理") -> 部门管理
Tag classTag = AnnotationUtil.getAnnotation(targetClass, Tag.class);
if (null != classTag) {
String name = classTag.name();
logRecord.setModule(CharSequenceUtil.blankToDefault(name, "请在该接口类上指定所属模块"));
}
}
}