Search in sources :

Example 1 with OperateLog

use of com.dimple.project.log.domain.OperateLog in project DimpleBlog by martin-chips.

the class LogAspect method handleLog.

/**
 * for log record
 *
 * @param joinPoint  join point
 * @param e          exception
 * @param jsonResult result
 * @param cost       the time of this method cost
 */
protected void handleLog(final JoinPoint joinPoint, final Exception e, Object jsonResult, long cost) {
    try {
        // get annotation
        Log controllerLog = getAnnotationLog(joinPoint);
        if (controllerLog == null) {
            return;
        }
        // get current user from servlet
        LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
        OperateLog operateLog = new OperateLog();
        operateLog.setStatus(Constants.SUCCESS);
        // get the IP of this request
        operateLog.setIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
        // get result with JSON format
        operateLog.setJsonResult(JSON.toJSONString(jsonResult));
        operateLog.setCost(cost);
        operateLog.setUrl(ServletUtils.getRequest().getRequestURI());
        if (loginUser != null) {
            operateLog.setOperateName(loginUser.getUsername());
        }
        if (e != null) {
            operateLog.setStatus(Constants.FAILED);
            operateLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000));
        }
        // get the class name
        String className = joinPoint.getTarget().getClass().getName();
        // get method name
        String methodName = joinPoint.getSignature().getName();
        operateLog.setMethod(StringUtils.format("{}.{}()", className, methodName));
        // get request method
        operateLog.setRequestMethod(ServletUtils.getRequest().getMethod());
        // set method args
        getControllerMethodDescription(joinPoint, controllerLog, operateLog);
        // save log
        AsyncManager.me().execute(AsyncFactory.recordOperateLog(operateLog));
    } catch (Exception exception) {
        log.error("get exception in handleLog,{} ", exception.getMessage(), exception);
    }
}
Also used : OperateLog(com.dimple.project.log.domain.OperateLog) Log(com.dimple.framework.aspectj.lang.annotation.Log) LoginUser(com.dimple.framework.security.LoginUser) TokenService(com.dimple.framework.security.service.TokenService) OperateLog(com.dimple.project.log.domain.OperateLog)

Example 2 with OperateLog

use of com.dimple.project.log.domain.OperateLog in project DimpleBlog by martin-chips.

the class AddressUpdateTask method updateOperateLogAddress.

private String updateOperateLogAddress() {
    List<OperateLog> operateLogList = operateLogMapper.selectOperateLogList(new OperateLog());
    Integer count = 0;
    for (OperateLog operateLog : operateLogList) {
        String ip = operateLog.getIp();
        if (StringUtils.isNotEmpty(ip)) {
            count++;
            String cityInfoByIp = AddressUtils.getCityInfoByIp(ip);
            operateLog.setLocation(cityInfoByIp);
            operateLogMapper.updateOperateLog(operateLog);
        }
    }
    return "OperateLog总数:" + operateLogList.size() + ";更新总数:" + count;
}
Also used : OperateLog(com.dimple.project.log.domain.OperateLog)

Example 3 with OperateLog

use of com.dimple.project.log.domain.OperateLog in project DimpleBlog by martin-chips.

the class DashboardServiceImpl method getOperateLogStringList.

@Override
public List<String> getOperateLogStringList() {
    List<OperateLog> operateLogList = dashBoardMapper.getOperateLogList();
    List<String> result = new LinkedList<>();
    Map<String, String> operateTypeString = getOperateTypeString();
    for (OperateLog operateLog : operateLogList) {
        Integer businessType = operateLog.getBusinessType();
        String typeString = operateTypeString.get(businessType.toString());
        result.add(StringUtils.format("{} : {} 对 {} 进行 {} 操作 {} {}", DateUtils.showTime(operateLog.getCreateTime()), operateLog.getOperateName(), operateLog.getTitle(), typeString, operateLog.getStatus().booleanValue() ? "成功" : "失败", operateLog.getStatus().booleanValue() ? "" : ",异常信息:" + operateLog.getErrorMsg()));
    }
    return result;
}
Also used : LinkedList(java.util.LinkedList) OperateLog(com.dimple.project.log.domain.OperateLog)

Aggregations

OperateLog (com.dimple.project.log.domain.OperateLog)3 Log (com.dimple.framework.aspectj.lang.annotation.Log)1 LoginUser (com.dimple.framework.security.LoginUser)1 TokenService (com.dimple.framework.security.service.TokenService)1 LinkedList (java.util.LinkedList)1