blob: 4ca862146562088a49f347c121760960b450fec8 (
plain)
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
|
package com.example.spring.aop.aoplogger;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
public class Logger {
public void beforMethodExecuted(JoinPoint joinPoint) {
System.out.println("AOP Logger (BEFORE): " + joinPoint.getSignature());
}
public void afterMethodExecuted(JoinPoint joinPoint) {
System.out.println("AOP Logger (AFTER): " + joinPoint.getSignature());
}
public Object methodExecutionMonitor(ProceedingJoinPoint pjp) throws Throwable {
long startTime = System.nanoTime();
Object retVal = pjp.proceed();
long endTime = System.nanoTime();
System.out.println("Method execution time (ns): " + pjp.getSignature() + " " + (endTime - startTime));
return retVal;
}
}
|