Last active
October 18, 2023 06:12
-
-
Save yashb042/d9a0797353cc749642a54b9703898230 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.example; | |
import org.aspectj.lang.ProceedingJoinPoint; | |
import org.aspectj.lang.annotation.Around; | |
import org.aspectj.lang.annotation.Aspect; | |
import org.aspectj.lang.reflect.MethodSignature; | |
import java.lang.reflect.Method; | |
@Aspect | |
public class MyAspect { | |
@Around("(execution(* org.example.Operator.*(..)) ||" + | |
"execution(* org.example.Customer.*(..)) ||" + | |
"execution(* org.example.food_items..*.*(..)) ||" + | |
"execution(* org.example.ingredients..*.*(..)) ||" + | |
"execution(* org.example.machines..*.*(..)))") | |
public Object logTimes(final ProceedingJoinPoint point) throws Throwable { | |
final Method method = ((MethodSignature) point.getSignature()).getMethod(); | |
final long start = System.nanoTime(); | |
try { | |
final Object result = point.proceed(); | |
final long nano = System.nanoTime() - start; | |
final long millis = nano / 1000000; | |
if (millis != 0) | |
System.out.println("Aspect method success - functionName - " + method.getName() + " , time - " + millis); | |
return result; | |
} catch (final Throwable ex) { | |
System.out.println("Aspect method failed - functionName - " + method.getName()); | |
throw ex; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment