Last active
February 3, 2017 06:58
-
-
Save r-winkler/6b62d0483b61ae0c280c35784da7f18c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Aspect | |
@Order(Ordered.LOWEST_PRECEDENCE) | |
@Component | |
public class LoggerAspect { | |
private Logger logger; | |
public LoggerAspect() { | |
logger = LoggerFactory.getLogger(getClass()); | |
} | |
@Pointcut("@annotation(org.springframework.web.bind.annotation.RequestMapping)") | |
public void requestMapping() { | |
} | |
@Pointcut("@annotation(com.xovis.standalone_multisensor.aspects.Profiled)") | |
public void profiled() { | |
} | |
@Around("requestMapping() || profiled()") | |
public Object profile(ProceedingJoinPoint pjp) throws Throwable { | |
StopWatch sw = new StopWatch(); | |
String className = pjp.getTarget().getClass().getSimpleName(); | |
String methodName = pjp.getSignature().getName(); | |
String name = className + "." + methodName; | |
logger.debug("call " + name); | |
try { | |
sw.start(); | |
return pjp.proceed(); | |
} finally { | |
sw.stop(); | |
logger.debug("exit " + name + " [" + sw.getTotalTimeMillis() + "ms]"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment