Search in sources :

Example 1 with AgileLoggerOperate

use of com.jeeagile.logger.entity.AgileLoggerOperate in project jeeagile by jeeagile.

the class AgileLoggerAspect method getAgileLoggerOperate.

/**
 * 封装操作日志对象参数
 *
 * @param httpServletRequest
 * @param throwable
 * @return
 */
private AgileLoggerOperate getAgileLoggerOperate(HttpServletRequest httpServletRequest, Throwable throwable) {
    AgileLoggerOperate agileLoggerOperate = new AgileLoggerOperate();
    AgileBaseUser userData = AgileSecurityContext.getCurrentUser();
    if (userData != null) {
        agileLoggerOperate.setOperateUser(userData.getUserName());
        agileLoggerOperate.setCreateUser(userData.getUserId());
        agileLoggerOperate.setUpdateUser(userData.getUserId());
    }
    agileLoggerOperate.setRequestUri(httpServletRequest.getRequestURI());
    agileLoggerOperate.setRequestMethod(httpServletRequest.getMethod());
    agileLoggerOperate.setOperateIp(AgileAgentUtil.getUserClientIp(httpServletRequest));
    String serverAddress = AgileSystemUtil.getHostInfo().getAddress() + ":" + this.serverPort;
    agileLoggerOperate.setServerAddress(serverAddress);
    UserAgent userAgent = AgileAgentUtil.getUserAgent(httpServletRequest);
    agileLoggerOperate.setOperateOs(userAgent.getOperatingSystem().getName());
    agileLoggerOperate.setOperateDevice(userAgent.getOperatingSystem().getDeviceType().getName());
    agileLoggerOperate.setOperateBrowser(userAgent.getBrowser().getName());
    if (throwable != null) {
        agileLoggerOperate.setStatus(AgileCommonStatus.FAIL.getCode());
        String excMessage = throwable.getMessage();
        if (excMessage.length() > 200) {
            agileLoggerOperate.setMessage(excMessage.substring(200));
        } else {
            agileLoggerOperate.setMessage(excMessage);
        }
    } else {
        agileLoggerOperate.setStatus(AgileCommonStatus.SUCCESS.getCode());
    }
    return agileLoggerOperate;
}
Also used : AgileLoggerOperate(com.jeeagile.logger.entity.AgileLoggerOperate) UserAgent(eu.bitwalker.useragentutils.UserAgent) AgileBaseUser(com.jeeagile.core.security.user.AgileBaseUser)

Example 2 with AgileLoggerOperate

use of com.jeeagile.logger.entity.AgileLoggerOperate in project jeeagile by jeeagile.

the class AgileLoggerAspect method saveAgileLoggerOperate.

/**
 * 保存日志
 *
 * @param joinPoint
 * @param throwable
 * @param executeTime
 */
private void saveAgileLoggerOperate(ProceedingJoinPoint joinPoint, Throwable throwable, Object rtnObject, long executeTime) {
    try {
        // AgileLogger agileLogger = joinPoint.getTarget().getClass().getAnnotation(AgileLogger.class);
        MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
        Method method = methodSignature.getMethod();
        AgileLogger agileLogger = method.getAnnotation(AgileLogger.class);
        ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        if (agileLogger != null && servletRequestAttributes != null) {
            HttpServletRequest httpServletRequest = servletRequestAttributes.getRequest();
            if (agileLogger.type() == AgileLoggerType.LOGIN) {
                AgileLoginUser agileLoginUser = null;
                for (Object object : joinPoint.getArgs()) {
                    if (object instanceof AgileLoginUser) {
                        agileLoginUser = (AgileLoginUser) object;
                        break;
                    }
                }
                if (agileLoginUser == null) {
                    log.warn("用户登录接口参数不是《AgileLoggerLogin》,暂无法记录登录信息!");
                    return;
                }
                AgileLoggerLogin agileLoggerLogin = getAgileLoggerLogin(httpServletRequest, throwable);
                agileLoggerLogin.setLoginName(agileLoginUser.getUserName());
                agileLoggerLogin.setLoginModule(getModuleName(joinPoint, agileLogger));
                agileLoggerAsyncTask.saveAgileLoggerLogin(agileLoggerLogin);
            } else {
                AgileLoggerOperate agileLoggerOperate = getAgileLoggerOperate(httpServletRequest, throwable);
                agileLoggerOperate.setOperateModule(getModuleName(joinPoint, agileLogger));
                agileLoggerOperate.setOperateNotes(agileLogger.notes());
                agileLoggerOperate.setOperateType(agileLogger.type().name());
                agileLoggerOperate.setExecuteTime(executeTime);
                String className = joinPoint.getTarget().getClass().getName();
                String methodName = joinPoint.getSignature().getName();
                agileLoggerOperate.setExecuteMethod(className + ":" + methodName);
                if (this.isSaveParam(joinPoint, agileLogger)) {
                    this.putParam(joinPoint, rtnObject, agileLoggerOperate);
                }
                agileLoggerAsyncTask.saveAgileLoggerOperate(agileLoggerOperate);
            }
        }
    } catch (Exception ex) {
        log.warn("日志记录出现异常,异常信息:{}", ex.getMessage());
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AgileLoggerOperate(com.jeeagile.logger.entity.AgileLoggerOperate) MethodSignature(org.aspectj.lang.reflect.MethodSignature) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) AgileLoggerLogin(com.jeeagile.logger.entity.AgileLoggerLogin) AgileLoginUser(com.jeeagile.core.security.user.AgileLoginUser) Method(java.lang.reflect.Method) AgileLogger(com.jeeagile.frame.annotation.AgileLogger)

Aggregations

AgileLoggerOperate (com.jeeagile.logger.entity.AgileLoggerOperate)2 AgileBaseUser (com.jeeagile.core.security.user.AgileBaseUser)1 AgileLoginUser (com.jeeagile.core.security.user.AgileLoginUser)1 AgileLogger (com.jeeagile.frame.annotation.AgileLogger)1 AgileLoggerLogin (com.jeeagile.logger.entity.AgileLoggerLogin)1 UserAgent (eu.bitwalker.useragentutils.UserAgent)1 Method (java.lang.reflect.Method)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 MethodSignature (org.aspectj.lang.reflect.MethodSignature)1 ServletRequestAttributes (org.springframework.web.context.request.ServletRequestAttributes)1