From 326dd76c34476141c39add5348da052bdb8c27cd Mon Sep 17 00:00:00 2001 From: Charles7c Date: Sun, 12 Jan 2025 22:58:29 +0800 Subject: [PATCH] =?UTF-8?q?refactor(log):=20=E8=B0=83=E6=95=B4=E6=89=80?= =?UTF-8?q?=E5=B1=9E=E6=A8=A1=E5=9D=97=E3=80=81=E6=97=A5=E5=BF=97=E6=8F=8F?= =?UTF-8?q?=E8=BF=B0=E9=BB=98=E8=AE=A4=E6=8F=90=E7=A4=BA=EF=BC=8C=E4=B8=8D?= =?UTF-8?q?=E5=86=8D=E7=9B=B4=E6=8E=A5=E6=8A=9B=E5=87=BA=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../continew/starter/log/AbstractLogHandler.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) 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 9a01e30f..b385719e 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 @@ -22,7 +22,6 @@ 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; @@ -83,6 +82,7 @@ public abstract class AbstractLogHandler implements LogHandler { */ @Override public void logDescription(LogRecord logRecord, Method targetMethod) { + logRecord.setDescription("请在该接口方法上添加 @top.continew.starter.log.annotation.Log(value) 来指定日志描述"); Log methodLog = AnnotationUtil.getAnnotation(targetMethod, Log.class); // 例如:@Log("新增部门") -> 新增部门 if (null != methodLog && CharSequenceUtil.isNotBlank(methodLog.value())) { @@ -91,11 +91,9 @@ public abstract class AbstractLogHandler implements LogHandler { } // 例如:@Operation(summary="新增部门") -> 新增部门 Operation methodOperation = AnnotationUtil.getAnnotation(targetMethod, Operation.class); - if (null != methodOperation) { - logRecord.setDescription(CharSequenceUtil.blankToDefault(methodOperation - .summary(), "请在该接口方法的 @Operation 上添加 summary 来指定日志描述")); + if (null != methodOperation && CharSequenceUtil.isNotBlank(methodOperation.summary())) { + logRecord.setDescription(methodOperation.summary()); } - ValidationUtils.throwIfBlank(logRecord.getDescription(), "请在该接口方法上添加 @Log 来指定日志描述"); } /** @@ -107,6 +105,7 @@ public abstract class AbstractLogHandler implements LogHandler { */ @Override public void logModule(LogRecord logRecord, Method targetMethod, Class targetClass) { + logRecord.setModule("请在该接口方法或类上添加 @top.continew.starter.log.annotation.Log(module) 来指定所属模块"); Log methodLog = AnnotationUtil.getAnnotation(targetMethod, Log.class); // 例如:@Log(module = "部门管理") -> 部门管理 // 方法级注解优先级高于类级注解 @@ -121,11 +120,9 @@ public abstract class AbstractLogHandler implements LogHandler { } // 例如:@Tag(name = "部门管理") -> 部门管理 Tag classTag = AnnotationUtil.getAnnotation(targetClass, Tag.class); - if (null != classTag) { - String name = classTag.name(); - logRecord.setModule(CharSequenceUtil.blankToDefault(name, "请在该接口类的 @Tag 上添加 name 来指定所属模块")); + if (null != classTag && CharSequenceUtil.isNotBlank(classTag.name())) { + logRecord.setModule(classTag.name()); } - ValidationUtils.throwIfBlank(logRecord.getModule(), "请在该接口方法或接口类上添加 @Log 来指定所属模块"); } @Override