EasyLog - Logging Interfaces



If you want to log interface’s method in all interface implementations then you can enable that feature by adding LoggerExtension like that

@Aspect
@Component
public class LoggerExtension extends EasyLoggerExtension {

    @Pointcut("execution(* com.yourcompany.yourapp..*.*(..))")
    public void anyMethodInPackage() {}

    @Around("anyMethodInPackage()")
    public Object method(ProceedingJoinPoint jp) throws Throwable {
        return logIfMethodHasAnnotatedInterface(jp);
    }

}

com.yourcompany.yourapp is your application package. It can be the root package or any specific package where your interfaces live.

Now you can annotate any method of any interface or any interface inside this package and its sub-packages.

It will apply for all implementations of the interface.

@LogIt(label = "All implemented methods of Interface")
public class Implementation implements Interface {

    public String methodWeWantToLog(String param) {
        return "methodWeWantToLog result";
    }
}
public class Implementation implements Interface {
    
    @LogIt(label = "methodWeWantToLog method of Interface")
    public String methodWeWantToLog(String param) {
        return "methodWeWantToLog result";
    }
}

LogIt can be used for the whole interface or for certain methods. See LogIt annotation priorities

Remember : To annotate classes, interfaces or their methods with @LogIt they should be a part of the Spring context. So for the interface/implementation example we used above it could be (see the @Component annotation)

@Component
@LogIt(label = "All implemented methods of Interface")
public class Implementation implements Interface {

    public String methodWeWantToLog(String param) {
        return "methodWeWantToLog result";
    }
}

and then you can inject it with @Autowired for example

@Autowired
Interface myImplementation;

See also EasyLog. Logging interface’s methods in all implementations