use of com.nb6868.onex.common.log.LogBody in project onex-boot by zhangchaoxu.
the class BaseExceptionHandler method saveLog.
/**
* 保存异常日志
*/
protected void saveLog(HttpServletRequest request, Exception ex) {
LogBody logEntity = new LogBody();
logEntity.setStoreType("db");
logEntity.setType("error");
logEntity.setState(0);
// 请求相关信息
if (request == null) {
request = HttpContextUtils.getHttpServletRequest();
}
if (null != request) {
logEntity.setUri(request.getRequestURI());
// 记录内容
Dict requestParams = Dict.create();
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 (HttpMethod.POST.name().equalsIgnoreCase(request.getMethod())) {
try {
requestParams.set("params", IoUtil.read(request.getInputStream()).toString());
} catch (IOException e) {
log.error("读取流失败", e);
}
}
logEntity.setRequestParams(requestParams);
}
// 异常信息
logEntity.setContent(ExceptionUtil.stacktraceToString(ex));
// 保存
try {
logService.saveLog(logEntity);
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.nb6868.onex.common.log.LogBody 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