From 8fdaa5d9293bbe31ead8f02148a0f8c8ec9ddfeb Mon Sep 17 00:00:00 2001 From: jasmine Date: Wed, 10 Jan 2024 08:32:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E5=9D=97=E5=92=8C=E6=8F=8F=E8=BF=B0?= =?UTF-8?q?=E4=BC=98=E5=85=88=E8=AF=BB=E5=8F=96@Log=E6=B3=A8=E8=A7=A3?= =?UTF-8?q?=E7=9A=84=EF=BC=8C=E8=8B=A5=E6=B2=A1=E6=9C=89@Log=E6=B3=A8?= =?UTF-8?q?=E8=A7=A3=E5=88=99=E8=8E=B7=E5=8F=96=E6=96=B9=E6=B3=95=E5=92=8C?= =?UTF-8?q?=E7=B1=BB=E4=B8=8A=E7=9A=84swagger=E6=B3=A8=E8=A7=A3=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../httptracepro/handler/LogInterceptor.java | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/continew-starter-log/continew-starter-log-httptrace-pro/src/main/java/top/charles7c/continew/starter/log/httptracepro/handler/LogInterceptor.java b/continew-starter-log/continew-starter-log-httptrace-pro/src/main/java/top/charles7c/continew/starter/log/httptracepro/handler/LogInterceptor.java index 5797eec1..623a8f76 100644 --- a/continew-starter-log/continew-starter-log-httptrace-pro/src/main/java/top/charles7c/continew/starter/log/httptracepro/handler/LogInterceptor.java +++ b/continew-starter-log/continew-starter-log-httptrace-pro/src/main/java/top/charles7c/continew/starter/log/httptracepro/handler/LogInterceptor.java @@ -104,15 +104,16 @@ public class LogInterceptor implements HandlerInterceptor { * @param handlerMethod 处理器方法 */ private void logDescription(LogRecord logRecord, HandlerMethod handlerMethod) { - // 例如:@Operation(summary="新增部门") -> 新增部门 - Operation methodOperation = handlerMethod.getMethodAnnotation(Operation.class); - if (null != methodOperation) { - logRecord.setDescription(StrUtil.blankToDefault(methodOperation.summary(), "请在该接口方法上指定日志描述")); - } // 例如:@Log("新增部门") -> 新增部门 Log methodLog = handlerMethod.getMethodAnnotation(Log.class); if (null != methodLog && StrUtil.isNotBlank(methodLog.value())) { logRecord.setDescription(methodLog.value()); + return; + } + // 例如:@Operation(summary="新增部门") -> 新增部门 + Operation methodOperation = handlerMethod.getMethodAnnotation(Operation.class); + if (null != methodOperation) { + logRecord.setDescription(StrUtil.blankToDefault(methodOperation.summary(), "请在该接口方法上指定日志描述")); } } @@ -123,21 +124,23 @@ public class LogInterceptor implements HandlerInterceptor { * @param handlerMethod 处理器方法 */ private void logModule(LogRecord logRecord, HandlerMethod handlerMethod) { + // 例如:@Log(module = "部门管理") -> 部门管理 + Log methodLog = handlerMethod.getMethodAnnotation(Log.class); + if (null != methodLog && StrUtil.isNotBlank(methodLog.module())) { + logRecord.setModule(methodLog.module()); + return; + } + Log classLog = handlerMethod.getBeanType().getDeclaredAnnotation(Log.class); + if(null != classLog && StrUtil.isNotBlank(classLog.module())) { + logRecord.setModule(classLog.module()); + return; + } // 例如:@Tag(name = "部门管理") -> 部门管理 Tag classTag = handlerMethod.getBeanType().getDeclaredAnnotation(Tag.class); if (null != classTag) { String name = classTag.name(); logRecord.setModule(StrUtil.blankToDefault(name, "请在该接口类上指定所属模块")); } - // 例如:@Log(module = "部门管理") -> 部门管理 - Log classLog = handlerMethod.getBeanType().getDeclaredAnnotation(Log.class); - if (null != classLog && StrUtil.isNotBlank(classLog.module())) { - logRecord.setModule(classLog.module()); - } - Log methodLog = handlerMethod.getMethodAnnotation(Log.class); - if (null != methodLog && StrUtil.isNotBlank(methodLog.module())) { - logRecord.setModule(methodLog.module()); - } } /**