use of com.nb6868.onex.common.annotation.LogOperation in project onex-boot by zhangchaoxu.
the class LogOperationAspect method saveLog.
/**
* 保存日志
*/
private void saveLog(ProceedingJoinPoint joinPoint, String params, long time, Integer state, Exception e) {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
LogBody logEntity = new LogBody();
// 日志记录类型
String storeType = "db";
String logType = "operation";
try {
Method method = joinPoint.getTarget().getClass().getDeclaredMethod(signature.getName(), signature.getParameterTypes());
LogOperation annotation = method.getAnnotation(LogOperation.class);
if (annotation != null) {
// 注解上的描述
logEntity.setOperation(annotation.value());
logType = annotation.type();
storeType = annotation.storeType();
}
} catch (NoSuchMethodException ne) {
ne.printStackTrace();
}
logEntity.setStoreType(storeType);
logEntity.setState(state);
logEntity.setRequestTime(time);
logEntity.setType(logType);
// 保存错误信息
if (e != null) {
logEntity.setContent(e instanceof OnexException ? e.toString() : ExceptionUtil.stacktraceToString(e));
}
// 请求参数
Dict requestParams = Dict.create().set("params", params);
HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
if (null != request) {
logEntity.setUri(request.getRequestURI());
// 记录内容
requestParams.set("ip", HttpContextUtils.getIpAddr(request));
requestParams.set("ua", request.getHeader(HttpHeaders.USER_AGENT));
requestParams.set("queryString", request.getQueryString());
requestParams.set("url", request.getRequestURL());
requestParams.set("method", request.getMethod());
requestParams.set("contentType", request.getContentType());
/*if (request instanceof OnexHttpServletRequestWrapper) {
try {
requestParams.set("params", IoUtil.read(request.getInputStream()).toString());
} catch (IOException ie) {
log.error("读取流失败", e);
}
}*/
}
logEntity.setRequestParams(requestParams);
logService.saveLog(logEntity);
}
Aggregations