-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathTransactionLoggingAspect.java
More file actions
34 lines (27 loc) · 1.09 KB
/
TransactionLoggingAspect.java
File metadata and controls
34 lines (27 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package ceos.backend.global.common.aop;
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;
import org.springframework.transaction.support.TransactionSynchronizationManager;
@Slf4j
@Aspect
@Component
public class TransactionLoggingAspect {
@Around("@annotation(ceos.backend.global.common.annotation.TransactionLog)")
public Object logTxMethod(ProceedingJoinPoint joinPoint) throws Throwable {
String methodName = joinPoint.getSignature().toShortString();
log.info("[TX START] {}", methodName);
String txName = TransactionSynchronizationManager.getCurrentTransactionName();
log.info("[TX NAME] = {}", txName);
try {
Object result = joinPoint.proceed();
log.info("[TX COMMIT] {}", methodName);
return result;
} catch (Exception e) {
log.warn("[TX ROLLBACK] {} - Exception: {}", methodName, e.getMessage());
throw e;
}
}
}