All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.kangjianqun.fast.common.log.aspect.SysLogAspect Maven / Gradle / Ivy

There is a newer version: 1.0.3
Show newest version
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