package com.jxd.Boot.aspect;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
/**
* @ClassName LoggingAspect
* @Description 日志切面
* @author jxd
* @Date 2018年6月4日 上午9:34:18
* @version 1.0.0
*/
@Aspect
@Component
public class LoggingAspect {
Logger logger = LoggerFactory.getLogger(getClass());
@Pointcut(value = "execution(public * com.jxd.Boot.web.*.*(..))")
public void webLog() {
}
/**
* @Description (前置通知)
* @param joinpoint
*/
@Before("webLog()")
public void dobefor(JoinPoint joinpoint) {
Signature signature = joinpoint.getSignature();
String typename = signature.getDeclaringTypeName();
String name = signature.getName();
logger.info("......................." + typename + "." + name + "()"
+ "方法进入.......................");
}
/**
* @Description (后置通知)
* @param ret
*/
@AfterReturning(returning = "ret", pointcut = "webLog()")
public void doafter(Object ret) {
logger.info("......................." + "返回值:" + ret+".......................");
}
/**
* @Description (异常通知)
* @param joinpoint
* @param e
*/
@AfterThrowing(value = "webLog()", throwing = "e")
public void afterexcetion(JoinPoint joinpoint, Exception e) {
Signature signature = joinpoint.getSignature();
String typename = signature.getDeclaringTypeName();
String name = signature.getName();
logger.info("......................." + typename + "." + name + "()"+"方法异常:"+e+".......................");
}
}