Last active
July 7, 2019 19:36
-
-
Save yusufcakal/3fc39784ba0bd89ade2940888497ae3f to your computer and use it in GitHub Desktop.
This custom annotation shows execution time that used method via aspect oriented programming in spring.
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
@Target(ElementType.METHOD) | |
@Retention(RetentionPolicy.RUNTIME) | |
public @interface LogExecutionTime { | |
} |
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
@Aspect | |
@Component | |
public class LogExecutionTimeAspect { | |
@Around("@annotation(LogExecutionTime)") | |
public void logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable { | |
long startTime = System.currentTimeMillis(); | |
joinPoint.proceed(); | |
String className = joinPoint.getTarget().getClass().getSimpleName(); | |
String methodName = joinPoint.getSignature().getName(); | |
Logger LOGGER = LoggerFactory.getLogger("Execution time of " + className + "." + methodName); | |
LOGGER.info(System.currentTimeMillis() - startTime + " ms"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment