Aspect
Annotation
package null-pointer.logger.annotation
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface MyLogger {
}
Aspect
package null-pointer.logger.aspect
@Aspect
public class MyLoggerAspect {
@Around("@annotation(null-pointer.logger.annotation.MyLogger)")
public Object invoke(ProceedingJoinPoint methodInvocation) throws Throwable {
MethodSignature signature = (MethodSignature) methodInvocation.getSignature();
String className = signature.getDeclaringTypeName();
String methodName = signature.getName();
logEvent(className, methodName, linkId, signature.getParameterNames(), "eventDirection=Request",
methodInvocation.getArgs());
try {
Object returnValue = methodInvocation.proceed();
if (returnValue != null) {
logEvent(className, methodName, linkId, NO_PARAMS, "eventDirection=Response", returnValue);
}
return returnValue;
} catch (Exception e) {
logEvent(className, methodName, linkId, NO_PARAMS, e.getMessage());
throw e;
}
}
}
Last updated