I created a custom class level annotation.
Below is the aspect class:
@Aspect
@Slf4j
@Component
public class LoggingAspect {
private String generateLogMessage() {
return ("Entering method");
}
@Before("@within(mypackage.logging.Loggable) || @annotation(mypackage.logging.Loggable)")
public void logMethodEntry(JoinPoint joinPoint) {
String logMessage = generateLogMessage();
log.debug(logMessage);
}
}
Below is my custom annotation:
@Target(value = {ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Loggable { }
When I use the annotation at class level it works. But if I am calling different methods within the same class the logging is done only once. I want to do the logging for each methods called using the class level @Loggable annotation.
I tried to use it at method level it works. But I want to use it at class level.