1 package dst.ass2.aop.logging;
3 import org.aspectj.lang.ProceedingJoinPoint;
4 import org.aspectj.lang.annotation.Around;
5 import org.aspectj.lang.annotation.Aspect;
7 import java.lang.reflect.Field;
8 import java.util.logging.Logger;
11 public class LoggingAspect {
12 @Around("execution(* dst.ass2.aop.IPluginExecutable.execute(..)) && !@annotation(Invisible)")
13 public Object around(ProceedingJoinPoint point) {
14 //try to get logger, if one exists.
16 for (Field f : point.getTarget().getClass().getDeclaredFields()) {
17 if (f.getType().isAssignableFrom(Logger.class)) {
19 boolean accessible = f.isAccessible();
20 f.setAccessible(true);
21 logger = (Logger) f.get(point.getTarget());
22 f.setAccessible(accessible);
23 } catch (IllegalAccessException ignored) {
30 logger.info("Plugin " + point.getTarget().getClass() + " started to execute");
32 System.out.println("Plugin " + point.getTarget().getClass() + " started to execute");
35 //execute actual function
38 result = point.proceed();
39 } catch (Throwable throwable) {
40 throwable.printStackTrace();
45 logger.info("Plugin " + point.getTarget().getClass() + " is finished");
47 System.out.println("Plugin " + point.getTarget().getClass() + " is finished");