diff --git a/continew-starter-log/continew-starter-log-aop/src/main/java/top/continew/starter/log/handler/AopLogHandler.java b/continew-starter-log/continew-starter-log-aop/src/main/java/top/continew/starter/log/handler/AopLogHandler.java index 2ce621f..203b392 100644 --- a/continew-starter-log/continew-starter-log-aop/src/main/java/top/continew/starter/log/handler/AopLogHandler.java +++ b/continew-starter-log/continew-starter-log-aop/src/main/java/top/continew/starter/log/handler/AopLogHandler.java @@ -16,11 +16,7 @@ package top.continew.starter.log.handler; -import cn.hutool.core.text.CharSequenceUtil; import top.continew.starter.log.AbstractLogHandler; -import top.continew.starter.log.model.LogRecord; - -import java.lang.reflect.Method; /** * 日志处理器-AOP 版实现 @@ -29,20 +25,4 @@ * @since 2.8.0 */ public class AopLogHandler extends AbstractLogHandler { - - @Override - public void logDescription(LogRecord logRecord, Method targetMethod) { - super.logDescription(logRecord, targetMethod); - if (CharSequenceUtil.isBlank(logRecord.getDescription())) { - logRecord.setDescription("请在该接口方法上指定日志描述"); - } - } - - @Override - public void logModule(LogRecord logRecord, Method targetMethod, Class targetClass) { - super.logModule(logRecord, targetMethod, targetClass); - if (CharSequenceUtil.isBlank(logRecord.getModule())) { - logRecord.setModule("请在该接口类上指定所属模块"); - } - } } diff --git a/continew-starter-log/continew-starter-log-core/pom.xml b/continew-starter-log/continew-starter-log-core/pom.xml index a972b57..52e4489 100644 --- a/continew-starter-log/continew-starter-log-core/pom.xml +++ b/continew-starter-log/continew-starter-log-core/pom.xml @@ -11,4 +11,12 @@ continew-starter-log-core ContiNew Starter 日志模块 - 核心模块 + + + + + io.swagger.core.v3 + swagger-annotations-jakarta + + \ No newline at end of file diff --git a/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/AbstractLogHandler.java b/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/AbstractLogHandler.java index 33a46d7..9a3df38 100644 --- a/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/AbstractLogHandler.java +++ b/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/AbstractLogHandler.java @@ -18,8 +18,11 @@ 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 jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import top.continew.starter.core.validation.ValidationUtils; import top.continew.starter.log.annotation.Log; import top.continew.starter.log.enums.Include; import top.continew.starter.log.http.servlet.RecordableServletHttpRequest; @@ -85,6 +88,13 @@ public void logDescription(LogRecord logRecord, Method targetMethod) { if (null != methodLog && CharSequenceUtil.isNotBlank(methodLog.value())) { logRecord.setDescription(methodLog.value()); } + // 例如:@Operation(summary="新增部门") -> 新增部门 + Operation methodOperation = AnnotationUtil.getAnnotation(targetMethod, Operation.class); + if (null != methodOperation) { + logRecord.setDescription(CharSequenceUtil.blankToDefault(methodOperation + .summary(), "请在该接口方法的 @Operation 上添加 summary 来指定日志描述")); + } + ValidationUtils.throwIfBlank(logRecord.getDescription(), "请在该接口方法上添加 @Log 来指定日志描述"); } /** @@ -107,6 +117,13 @@ public void logModule(LogRecord logRecord, Method targetMethod, Class targetC if (null != classLog && CharSequenceUtil.isNotBlank(classLog.module())) { logRecord.setModule(classLog.module()); } + // 例如:@Tag(name = "部门管理") -> 部门管理 + Tag classTag = AnnotationUtil.getAnnotation(targetClass, Tag.class); + if (null != classTag) { + String name = classTag.name(); + logRecord.setModule(CharSequenceUtil.blankToDefault(name, "请在该接口类的 @Tag 上添加 name 来指定所属模块")); + } + ValidationUtils.throwIfBlank(logRecord.getModule(), "请在该接口方法或接口类上添加 @Log 来指定所属模块"); } @Override diff --git a/continew-starter-log/continew-starter-log-interceptor/pom.xml b/continew-starter-log/continew-starter-log-interceptor/pom.xml index 8f96cea..6827794 100644 --- a/continew-starter-log/continew-starter-log-interceptor/pom.xml +++ b/continew-starter-log/continew-starter-log-interceptor/pom.xml @@ -13,12 +13,6 @@ ContiNew Starter 日志模块 - 基于拦截器实现(Spring Boot Actuator HttpTrace 增强版) - - - io.swagger.core.v3 - swagger-annotations-jakarta - - com.alibaba diff --git a/continew-starter-log/continew-starter-log-interceptor/src/main/java/top/continew/starter/log/handler/InterceptorLogHandler.java b/continew-starter-log/continew-starter-log-interceptor/src/main/java/top/continew/starter/log/handler/InterceptorLogHandler.java index adffab8..1f3a4bd 100644 --- a/continew-starter-log/continew-starter-log-interceptor/src/main/java/top/continew/starter/log/handler/InterceptorLogHandler.java +++ b/continew-starter-log/continew-starter-log-interceptor/src/main/java/top/continew/starter/log/handler/InterceptorLogHandler.java @@ -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 @@ * @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, "请在该接口类上指定所属模块")); - } - } }