Search in sources :

Example 1 with OptLogDTO

use of com.whoiszxl.logger.entity.OptLogDTO in project shopzz by whoiszxl.

the class SSLogAspect method doAfterThrowable.

/**
 * 异常通知
 *
 * @param e
 */
@AfterThrowing(pointcut = "ssLogAspect()", throwing = "e")
public void doAfterThrowable(Throwable e) {
    tryCatch((aaa) -> {
        OptLogDTO sysLog = get();
        sysLog.setType("EX");
        // 异常对象
        sysLog.setExDetail(LogUtil.getStackTrace(e));
        // 异常信息
        sysLog.setExDesc(e.getMessage());
        publishEvent(sysLog);
    });
}
Also used : OptLogDTO(com.whoiszxl.logger.entity.OptLogDTO)

Example 2 with OptLogDTO

use of com.whoiszxl.logger.entity.OptLogDTO in project shopzz by whoiszxl.

the class SSLogAspect method recordLog.

@Before(value = "ssLogAspect()")
public void recordLog(JoinPoint joinPoint) throws Throwable {
    tryCatch((val) -> {
        // 开始时间
        OptLogDTO sysLog = get();
        sysLog.setCreateUser(BaseContextHandler.getUserId());
        sysLog.setUserName(BaseContextHandler.getName());
        String controllerDescription = "";
        Api api = joinPoint.getTarget().getClass().getAnnotation(Api.class);
        if (api != null) {
            String[] tags = api.tags();
            if (tags != null && tags.length > 0) {
                controllerDescription = tags[0];
            }
        }
        String controllerMethodDescription = LogUtil.getControllerMethodDescription(joinPoint);
        if (StrUtil.isEmpty(controllerDescription)) {
            sysLog.setDescription(controllerMethodDescription);
        } else {
            sysLog.setDescription(controllerDescription + "-" + controllerMethodDescription);
        }
        // 类名
        sysLog.setClassPath(joinPoint.getTarget().getClass().getName());
        // 获取执行的方法名
        sysLog.setActionMethod(joinPoint.getSignature().getName());
        // 参数
        Object[] args = joinPoint.getArgs();
        String strArgs = "";
        HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
        try {
            if (!request.getContentType().contains("multipart/form-data")) {
                strArgs = JsonUtil.toJson(args);
            }
        } catch (Exception e) {
            try {
                strArgs = Arrays.toString(args);
            } catch (Exception ex) {
                log.warn("解析参数异常", ex);
            }
        }
        sysLog.setParams(getText(strArgs));
        if (request != null) {
            sysLog.setRequestIp(ServletUtil.getClientIP(request));
            sysLog.setRequestUri(URLUtil.getPath(request.getRequestURI()));
            sysLog.setHttpMethod(request.getMethod());
            sysLog.setUa(StrUtil.sub(request.getHeader("user-agent"), 0, 500));
        }
        sysLog.setStartTime(LocalDateTime.now());
        THREAD_LOCAL.set(sysLog);
    });
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) Api(io.swagger.annotations.Api) OptLogDTO(com.whoiszxl.logger.entity.OptLogDTO)

Example 3 with OptLogDTO

use of com.whoiszxl.logger.entity.OptLogDTO in project shopzz by whoiszxl.

the class SSLogAspect method doAfterReturning.

/**
 * 返回通知
 *
 * @param ret
 * @throws Throwable
 */
@AfterReturning(returning = "ret", pointcut = "ssLogAspect()")
public void doAfterReturning(Object ret) {
    tryCatch((aaa) -> {
        ResponseResult r = Convert.convert(ResponseResult.class, ret);
        OptLogDTO sysLog = get();
        if (r == null) {
            sysLog.setType("OPT");
        } else {
            if (r.isOk()) {
                sysLog.setType("OPT");
            } else {
                sysLog.setType("EX");
                sysLog.setExDetail(r.getMessage());
            }
            sysLog.setResult(getText(r.toString()));
        }
        publishEvent(sysLog);
    });
}
Also used : ResponseResult(com.whoiszxl.bean.ResponseResult) OptLogDTO(com.whoiszxl.logger.entity.OptLogDTO)

Example 4 with OptLogDTO

use of com.whoiszxl.logger.entity.OptLogDTO in project shopzz by whoiszxl.

the class SysLogListener method saveSysLog.

@Async
@Order
@EventListener(SysLogEvent.class)
public void saveSysLog(SysLogEvent event) {
    OptLogDTO optLog = (OptLogDTO) event.getSource();
    consumer.accept(optLog);
}
Also used : OptLogDTO(com.whoiszxl.logger.entity.OptLogDTO) Order(org.springframework.core.annotation.Order) Async(org.springframework.scheduling.annotation.Async) EventListener(org.springframework.context.event.EventListener)

Aggregations

OptLogDTO (com.whoiszxl.logger.entity.OptLogDTO)4 ResponseResult (com.whoiszxl.bean.ResponseResult)1 Api (io.swagger.annotations.Api)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 EventListener (org.springframework.context.event.EventListener)1 Order (org.springframework.core.annotation.Order)1 Async (org.springframework.scheduling.annotation.Async)1 ServletRequestAttributes (org.springframework.web.context.request.ServletRequestAttributes)1