Saturday, March 21, 2020

Aspects to log enter and exit method

https://github.com/vernetto/logaspect

The idea is:

use @EnableAspectJAutoProxy in a @Configuration

create an annotation EntryExitLogger to mark the method(s) you want to be logged for entry/exit

have a @Component annotated with @Aspect and inside it you specify the aspects:

@Around("@annotation(EntryExitLogger)")
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable{
}


That's all.

Detailed post on the topic https://medium.com/@wkrzywiec/moving-into-next-level-in-user-log-events-with-spring-aop-3b4435892f16

Doc of AspectJ here https://docs.spring.io/spring/docs/2.0.x/reference/aop.html

Good Aspectj cookbock here https://blog.espenberntsen.net/2010/03/20/aspectj-cheat-sheet/

No comments: