Skip to content

Commit aa03fb1

Browse files
committed
feat(logging): add Loggable annotation and LoggingMethodAspect for method execution logging
1 parent 2269fce commit aa03fb1

3 files changed

Lines changed: 45 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.park.utmstack.aop.logging;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
@Target(ElementType.METHOD)
9+
@Retention(RetentionPolicy.RUNTIME)
10+
public @interface Loggable {
11+
}
12+
13+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.park.utmstack.aop.logging.impl;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import org.aspectj.lang.ProceedingJoinPoint;
5+
import org.aspectj.lang.annotation.Around;
6+
import org.aspectj.lang.annotation.Aspect;
7+
import org.slf4j.MDC;
8+
import org.springframework.stereotype.Component;
9+
10+
@Aspect
11+
@Component
12+
@Slf4j
13+
public class LoggingMethodAspect {
14+
@Around("@annotation(com.park.utmstack.aop.logging.Loggable)")
15+
public Object logExecution(ProceedingJoinPoint joinPoint) throws Throwable {
16+
String traceId = MDC.get("traceId");
17+
String methodName = joinPoint.getSignature().toShortString();
18+
long start = System.currentTimeMillis();
19+
20+
try {
21+
Object result = joinPoint.proceed();
22+
long duration = System.currentTimeMillis() - start;
23+
log.debug("[{}] Method {} executed successfully in {}ms", traceId, methodName, duration);
24+
return result;
25+
} catch (Exception ex) {
26+
log.error("[{}] Method {} failed: {}", traceId, methodName, ex.getMessage(), ex);
27+
throw ex;
28+
}
29+
}
30+
}

backend/src/main/java/com/park/utmstack/service/tfa/TotpTfaService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.google.zxing.MultiFormatWriter;
55
import com.google.zxing.client.j2se.MatrixToImageWriter;
66
import com.google.zxing.common.BitMatrix;
7+
import com.park.utmstack.aop.logging.Loggable;
78
import com.park.utmstack.config.Constants;
89
import com.park.utmstack.domain.User;
910
import com.park.utmstack.domain.tfa.TfaMethod;
@@ -58,6 +59,7 @@ public TfaInitResponse initiateSetup(User user) {
5859
}
5960

6061
@Override
62+
@Loggable
6163
public TfaVerifyResponse verifyCode(User user, String code) {
6264
TfaSetupState tfaSetupState = cache.getState(user.getLogin(), TfaMethod.TOTP)
6365
.orElseThrow(() -> new IllegalStateException("No TFA setup found for user: " + user.getLogin()));

0 commit comments

Comments
 (0)