io.github.kangjianqun.fast.common.log.aspect.SysLogAspect Maven / Gradle / Ivy
package io.github.kangjianqun.fast.common.log.aspect;
import io.github.kangjianqun.fast.common.core.util.SpringContextHolder;
import io.github.kangjianqun.fast.common.log.annotation.ISysLog;
import io.github.kangjianqun.fast.common.log.event.ASysLog;
import io.github.kangjianqun.fast.common.log.event.SysLogEvent;
import io.github.kangjianqun.fast.common.log.util.LogTypeEnum;
import io.github.kangjianqun.fast.common.log.util.SysLogUtils;
import lombok.SneakyThrows;
import lombok.extern.log4j.Log4j2;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
/**
* 操作日志使用spring event 异步处理
*
* @author 康建群
*/
@Aspect
@Log4j2
public class SysLogAspect {
@Around("@annotation(ISysLog)")
@SneakyThrows
public Object around(ProceedingJoinPoint point, ISysLog ISysLog) {
String strClassName = point.getTarget().getClass().getName();
String strMethodName = point.getSignature().getName();
log.debug("[类名]: {},[方法]: {}", strClassName, strMethodName);
ASysLog logVo = SysLogUtils.getSysLog();
logVo.setTitle(ISysLog.value());
// 发送异步日志事件
Long startTime = System.currentTimeMillis();
Object obj;
try {
obj = point.proceed();
} catch (Exception e) {
logVo.setType(LogTypeEnum.ERROR.getType());
logVo.setException(e.getMessage());
throw e;
} finally {
Long endTime = System.currentTimeMillis();
logVo.setTime(endTime - startTime);
SpringContextHolder.publishEvent(new SysLogEvent(logVo));
}
return obj;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy