refactor(logging): 重构执行时间统计功能的注解和切面类命名
This commit is contained in:
+1
-1
@@ -31,7 +31,7 @@ import java.lang.annotation.Target;
|
|||||||
@Documented
|
@Documented
|
||||||
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface ExecutionTimeStatisticsFace {
|
public @interface ExecutionTimeLog {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 接口描述
|
* 接口描述
|
||||||
+6
-6
@@ -32,20 +32,20 @@ import org.springframework.stereotype.Component;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@Aspect
|
@Aspect
|
||||||
@Component
|
@Component
|
||||||
public class ExecutionTimeStatisticsFaceAspect {
|
public class ExecutionTimeLogAspect {
|
||||||
|
|
||||||
@Around("@annotation(executionTimeStatisticsFace)")
|
@Around("@annotation(executionTimeLog)")
|
||||||
public Object aroundFace(ProceedingJoinPoint joinPoint, ExecutionTimeStatisticsFace executionTimeStatisticsFace)
|
public Object aroundFace(ProceedingJoinPoint joinPoint, ExecutionTimeLog executionTimeLog)
|
||||||
throws Throwable {
|
throws Throwable {
|
||||||
TimeInterval timeInterval = new TimeInterval();
|
TimeInterval timeInterval = new TimeInterval();
|
||||||
try {
|
try {
|
||||||
Object proceed = joinPoint.proceed();
|
Object proceed = joinPoint.proceed();
|
||||||
log.info("[{}] 接口执行成功,耗时: {} ms", executionTimeStatisticsFace.description(),
|
log.info("[{}] 接口执行成功,耗时: {} ms", executionTimeLog.description(),
|
||||||
timeInterval.intervalMs());
|
timeInterval.intervalMs());
|
||||||
return proceed;
|
return proceed;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (executionTimeStatisticsFace.showErrLog()) {
|
if (executionTimeLog.showErrLog()) {
|
||||||
log.error("[{}] 接口执行失败,耗时: {} ms", executionTimeStatisticsFace.description(),
|
log.error("[{}] 接口执行失败,耗时: {} ms", executionTimeLog.description(),
|
||||||
timeInterval.intervalMs(), e);
|
timeInterval.intervalMs(), e);
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
+1
-1
@@ -31,7 +31,7 @@ import java.lang.annotation.Target;
|
|||||||
@Documented
|
@Documented
|
||||||
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface ExecutionTimeStatisticsFace {
|
public @interface ExecutionTimeLog {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 接口描述
|
* 接口描述
|
||||||
+6
-6
@@ -32,20 +32,20 @@ import org.springframework.stereotype.Component;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@Aspect
|
@Aspect
|
||||||
@Component
|
@Component
|
||||||
public class ExecutionTimeStatisticsFaceAspect {
|
public class ExecutionTimeLogAspect {
|
||||||
|
|
||||||
@Around("@annotation(executionTimeStatisticsFace)")
|
@Around("@annotation(executionTimeLog)")
|
||||||
public Object aroundFace(ProceedingJoinPoint joinPoint, ExecutionTimeStatisticsFace executionTimeStatisticsFace)
|
public Object aroundFace(ProceedingJoinPoint joinPoint, ExecutionTimeLog executionTimeLog)
|
||||||
throws Throwable {
|
throws Throwable {
|
||||||
TimeInterval timeInterval = new TimeInterval();
|
TimeInterval timeInterval = new TimeInterval();
|
||||||
try {
|
try {
|
||||||
Object proceed = joinPoint.proceed();
|
Object proceed = joinPoint.proceed();
|
||||||
log.info("[{}] 接口执行成功,耗时: {} ms", executionTimeStatisticsFace.description(),
|
log.info("[{}] 接口执行成功,耗时: {} ms", executionTimeLog.description(),
|
||||||
timeInterval.intervalMs());
|
timeInterval.intervalMs());
|
||||||
return proceed;
|
return proceed;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (executionTimeStatisticsFace.showErrLog()) {
|
if (executionTimeLog.showErrLog()) {
|
||||||
log.error("[{}] 接口执行失败,耗时: {} ms", executionTimeStatisticsFace.description(),
|
log.error("[{}] 接口执行失败,耗时: {} ms", executionTimeLog.description(),
|
||||||
timeInterval.intervalMs(), e);
|
timeInterval.intervalMs(), e);
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
Reference in New Issue
Block a user