Skip to content

Instantly share code, notes, and snippets.

@jangalinski
Created July 26, 2016 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jangalinski/dad0c09a5bd003366431743be1bad9ac to your computer and use it in GitHub Desktop.
Save jangalinski/dad0c09a5bd003366431743be1bad9ac to your computer and use it in GitHub Desktop.
@Aspect
public class LoggingAspect {
private static Logger logger = LoggerFactory.getLogger(LoggingAspect.class);
@Around("requiredLog()")
public Object logMethod(ProceedingJoinPoint proceedingJoinPoint) {
Object returnValue = null;
try {
logger.info("method -> " + proceedingJoinPoint.getSignature().toShortString()
+ ", arguments -> " + Arrays.asList(proceedingJoinPoint.getArgs()));
return proceedingJoinPoint.proceed();
} catch (Throwable e) {
logger.error("error -> " + e.getMessage());
} finally {
logger.info("ended -> " + proceedingJoinPoint.getSignature().toShortString());
}
}
@Pointcut("within(my.package..*)")
public void forAllPackages() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment