use of com.jeeagile.logger.entity.AgileLoggerLogin 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());
}
}
use of com.jeeagile.logger.entity.AgileLoggerLogin in project jeeagile by jeeagile.
the class AgileLoggerAspect method getAgileLoggerLogin.
private AgileLoggerLogin getAgileLoggerLogin(HttpServletRequest httpServletRequest, Throwable throwable) {
AgileLoggerLogin agileLoggerLogin = new AgileLoggerLogin();
agileLoggerLogin.setStatus(AgileCommonStatus.SUCCESS.getCode());
agileLoggerLogin.setLoginTime(new Date());
agileLoggerLogin.setLoginIp(AgileAgentUtil.getUserClientIp(httpServletRequest));
String serverAddress = AgileSystemUtil.getHostInfo().getAddress() + ":" + serverPort;
agileLoggerLogin.setServerAddress(serverAddress);
UserAgent userAgent = AgileAgentUtil.getUserAgent(httpServletRequest);
agileLoggerLogin.setLoginOs(userAgent.getOperatingSystem().getName());
agileLoggerLogin.setLoginDevice(userAgent.getOperatingSystem().getDeviceType().getName());
agileLoggerLogin.setLoginBrowser(userAgent.getBrowser().getName());
if (throwable != null) {
agileLoggerLogin.setStatus(AgileCommonStatus.FAIL.getCode());
String excMessage = throwable.getMessage();
if (excMessage.length() > 100) {
agileLoggerLogin.setMessage(excMessage.substring(100));
} else {
agileLoggerLogin.setMessage(throwable.getMessage());
}
} else {
agileLoggerLogin.setStatus(AgileCommonStatus.SUCCESS.getCode());
agileLoggerLogin.setMessage("登录成功");
}
return agileLoggerLogin;
}
Aggregations