From 6d486c5ba6c61396006b26579fa286687d0dd5a5 Mon Sep 17 00:00:00 2001 From: Odboy Date: Sat, 21 Feb 2026 21:41:12 +0800 Subject: [PATCH] =?UTF-8?q?refactor(logging):=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E6=97=B6=E9=97=B4=E7=BB=9F=E8=AE=A1=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E7=9A=84=E6=B3=A8=E8=A7=A3=E5=92=8C=E5=88=87=E9=9D=A2?= =?UTF-8?q?=E7=B1=BB=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...tisticsFace.java => ExecutionTimeLog.java} | 2 +- ...spect.java => ExecutionTimeLogAspect.java} | 12 +- ...tisticsFace.java => ExecutionTimeLog.java} | 90 +++++++-------- ...spect.java => ExecutionTimeLogAspect.java} | 108 +++++++++--------- 4 files changed, 106 insertions(+), 106 deletions(-) rename cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/logging/{ExecutionTimeStatisticsFace.java => ExecutionTimeLog.java} (96%) rename cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/logging/{ExecutionTimeStatisticsFaceAspect.java => ExecutionTimeLogAspect.java} (83%) rename cutejava/cutejava-framework/src/main/java/cn/odboy/framework/logging/{ExecutionTimeStatisticsFace.java => ExecutionTimeLog.java} (92%) rename cutejava/cutejava-framework/src/main/java/cn/odboy/framework/logging/{ExecutionTimeStatisticsFaceAspect.java => ExecutionTimeLogAspect.java} (81%) diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/logging/ExecutionTimeStatisticsFace.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/logging/ExecutionTimeLog.java similarity index 96% rename from cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/logging/ExecutionTimeStatisticsFace.java rename to cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/logging/ExecutionTimeLog.java index 930d7523..159e962f 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/logging/ExecutionTimeStatisticsFace.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/logging/ExecutionTimeLog.java @@ -31,7 +31,7 @@ import java.lang.annotation.Target; @Documented @Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) -public @interface ExecutionTimeStatisticsFace { +public @interface ExecutionTimeLog { /** * 接口描述 diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/logging/ExecutionTimeStatisticsFaceAspect.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/logging/ExecutionTimeLogAspect.java similarity index 83% rename from cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/logging/ExecutionTimeStatisticsFaceAspect.java rename to cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/logging/ExecutionTimeLogAspect.java index f36261b6..eb21c8fb 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/logging/ExecutionTimeStatisticsFaceAspect.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/logging/ExecutionTimeLogAspect.java @@ -32,20 +32,20 @@ import org.springframework.stereotype.Component; @Slf4j @Aspect @Component -public class ExecutionTimeStatisticsFaceAspect { +public class ExecutionTimeLogAspect { - @Around("@annotation(executionTimeStatisticsFace)") - public Object aroundFace(ProceedingJoinPoint joinPoint, ExecutionTimeStatisticsFace executionTimeStatisticsFace) + @Around("@annotation(executionTimeLog)") + public Object aroundFace(ProceedingJoinPoint joinPoint, ExecutionTimeLog executionTimeLog) throws Throwable { TimeInterval timeInterval = new TimeInterval(); try { Object proceed = joinPoint.proceed(); - log.info("[{}] 接口执行成功,耗时: {} ms", executionTimeStatisticsFace.description(), + log.info("[{}] 接口执行成功,耗时: {} ms", executionTimeLog.description(), timeInterval.intervalMs()); return proceed; } catch (Exception e) { - if (executionTimeStatisticsFace.showErrLog()) { - log.error("[{}] 接口执行失败,耗时: {} ms", executionTimeStatisticsFace.description(), + if (executionTimeLog.showErrLog()) { + log.error("[{}] 接口执行失败,耗时: {} ms", executionTimeLog.description(), timeInterval.intervalMs(), e); } throw e; diff --git a/cutejava/cutejava-framework/src/main/java/cn/odboy/framework/logging/ExecutionTimeStatisticsFace.java b/cutejava/cutejava-framework/src/main/java/cn/odboy/framework/logging/ExecutionTimeLog.java similarity index 92% rename from cutejava/cutejava-framework/src/main/java/cn/odboy/framework/logging/ExecutionTimeStatisticsFace.java rename to cutejava/cutejava-framework/src/main/java/cn/odboy/framework/logging/ExecutionTimeLog.java index 4ef08993..159e962f 100644 --- a/cutejava/cutejava-framework/src/main/java/cn/odboy/framework/logging/ExecutionTimeStatisticsFace.java +++ b/cutejava/cutejava-framework/src/main/java/cn/odboy/framework/logging/ExecutionTimeLog.java @@ -1,45 +1,45 @@ -/* - * Copyright 2021-2026 Odboy - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package cn.odboy.framework.logging; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Inherited; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * 统计执行时长(仅对代理方法有效) - * - * @author odboy - */ -@Inherited -@Documented -@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE}) -@Retention(RetentionPolicy.RUNTIME) -public @interface ExecutionTimeStatisticsFace { - - /** - * 接口描述 - */ - String description(); - - /** - * 是否展示异常日志 - */ - boolean showErrLog() default true; -} +/* + * Copyright 2021-2026 Odboy + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.odboy.framework.logging; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 统计执行时长(仅对代理方法有效) + * + * @author odboy + */ +@Inherited +@Documented +@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +public @interface ExecutionTimeLog { + + /** + * 接口描述 + */ + String description(); + + /** + * 是否展示异常日志 + */ + boolean showErrLog() default true; +} diff --git a/cutejava/cutejava-framework/src/main/java/cn/odboy/framework/logging/ExecutionTimeStatisticsFaceAspect.java b/cutejava/cutejava-framework/src/main/java/cn/odboy/framework/logging/ExecutionTimeLogAspect.java similarity index 81% rename from cutejava/cutejava-framework/src/main/java/cn/odboy/framework/logging/ExecutionTimeStatisticsFaceAspect.java rename to cutejava/cutejava-framework/src/main/java/cn/odboy/framework/logging/ExecutionTimeLogAspect.java index f019ce5b..eb21c8fb 100644 --- a/cutejava/cutejava-framework/src/main/java/cn/odboy/framework/logging/ExecutionTimeStatisticsFaceAspect.java +++ b/cutejava/cutejava-framework/src/main/java/cn/odboy/framework/logging/ExecutionTimeLogAspect.java @@ -1,54 +1,54 @@ -/* - * Copyright 2021-2026 Odboy - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.odboy.framework.logging; - -import cn.hutool.core.date.TimeInterval; -import lombok.extern.slf4j.Slf4j; -import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.annotation.Around; -import org.aspectj.lang.annotation.Aspect; -import org.springframework.stereotype.Component; - -/** - * 执行时间统计 - * - * @author odboy - * @date 2025-05-07 - */ -@Slf4j -@Aspect -@Component -public class ExecutionTimeStatisticsFaceAspect { - - @Around("@annotation(executionTimeStatisticsFace)") - public Object aroundFace(ProceedingJoinPoint joinPoint, ExecutionTimeStatisticsFace executionTimeStatisticsFace) - throws Throwable { - TimeInterval timeInterval = new TimeInterval(); - try { - Object proceed = joinPoint.proceed(); - log.info("[{}] 接口执行成功,耗时: {} ms", executionTimeStatisticsFace.description(), - timeInterval.intervalMs()); - return proceed; - } catch (Exception e) { - if (executionTimeStatisticsFace.showErrLog()) { - log.error("[{}] 接口执行失败,耗时: {} ms", executionTimeStatisticsFace.description(), - timeInterval.intervalMs(), e); - } - throw e; - } - } -} +/* + * Copyright 2021-2026 Odboy + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cn.odboy.framework.logging; + +import cn.hutool.core.date.TimeInterval; +import lombok.extern.slf4j.Slf4j; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.springframework.stereotype.Component; + +/** + * 执行时间统计 + * + * @author odboy + * @date 2025-05-07 + */ +@Slf4j +@Aspect +@Component +public class ExecutionTimeLogAspect { + + @Around("@annotation(executionTimeLog)") + public Object aroundFace(ProceedingJoinPoint joinPoint, ExecutionTimeLog executionTimeLog) + throws Throwable { + TimeInterval timeInterval = new TimeInterval(); + try { + Object proceed = joinPoint.proceed(); + log.info("[{}] 接口执行成功,耗时: {} ms", executionTimeLog.description(), + timeInterval.intervalMs()); + return proceed; + } catch (Exception e) { + if (executionTimeLog.showErrLog()) { + log.error("[{}] 接口执行失败,耗时: {} ms", executionTimeLog.description(), + timeInterval.intervalMs(), e); + } + throw e; + } + } +}