package jp.dip.arimodoki.common;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.aop.ThrowsAdvice;
import org.springframework.stereotype.Component;
@Aspect
@Component
public class LogAspect implements CConst ,ThrowsAdvice {
private static final String LABEL_ENTER = "() Enter";
private static final String LABEL_LEAVE = "() Leave";
private static final String LAYER_CONTROLLER = "jp.dip.arimodoki.cntl";
private static final String LAYER_SERVICE = "jp.dip.arimodoki.blogic";
public LogAspect() {}
private void logInfo(JoinPoint jp, String label) {
Class<?> cls = jp.getTarget().getClass();
String cName = jp.getTarget().getClass().getName();
String mName = jp.getSignature().getName();
String msg = "=="+cName+":"+mName+ label;
logger.log_info(cls, msg);
}
private void logError(Exception ex) {
logger.log_error(ex);
}
@Before("execution(* "+LAYER_CONTROLLER+".*.*(..))")
public void beforeController(JoinPoint jp) {
this.logInfo(jp, LABEL_ENTER);
}
@Before("execution(* "+LAYER_SERVICE+".*.*(..))")
public void beforeBlogic(JoinPoint jp) {
this.logInfo(jp, LABEL_ENTER);
}
@After("execution(* "+LAYER_CONTROLLER+".*.*(..))")
public void afterController(JoinPoint jp) {
this.logInfo(jp, LABEL_LEAVE);
}
@After("execution(* "+LAYER_SERVICE+".*.*(..))")
public void afterBlogic(JoinPoint jp) {
this.logInfo(jp, LABEL_LEAVE);
}
@AfterThrowing(pointcut="execution(* "+LAYER_CONTROLLER+".*.*(..))",throwing="ex")
public void afterThrowingController(Exception ex) throws Throwable {
this.logError(ex);
}
@AfterThrowing(pointcut="execution(* "+LAYER_SERVICE+".*.*(..))",throwing="ex")
public void afterThrowingBlogic(Exception ex) throws Throwable {
this.logError(ex);
}
}
|