|
@@ -50,7 +50,6 @@ public class HandleLogAspect {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private LogMapper logMapper;
|
|
private LogMapper logMapper;
|
|
|
|
|
|
|
|
- //@Pointcut("execution(* com.tuoren.forward.controller.*.*(..))")
|
|
|
|
|
@Pointcut("@annotation(com.tuoren.forward.annotation.HandleLog)")
|
|
@Pointcut("@annotation(com.tuoren.forward.annotation.HandleLog)")
|
|
|
public void handleLogPoint() {}
|
|
public void handleLogPoint() {}
|
|
|
|
|
|
|
@@ -79,10 +78,10 @@ public class HandleLogAspect {
|
|
|
public Object handleLogAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
|
public Object handleLogAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
|
|
HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
|
|
HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
long time = System.currentTimeMillis();
|
|
long time = System.currentTimeMillis();
|
|
|
- Log handleLog = packLog(request,joinPoint);
|
|
|
|
|
- MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
|
|
|
|
- Method method = signature.getMethod();
|
|
|
|
|
- HandleLog logAnno = method.getAnnotation(HandleLog.class);
|
|
|
|
|
|
|
+ Log handleLog = packLog(request,joinPoint);//打包日志信息
|
|
|
|
|
+ MethodSignature signature = (MethodSignature) joinPoint.getSignature();//获取签名
|
|
|
|
|
+ Method method = signature.getMethod();//获取方法
|
|
|
|
|
+ HandleLog logAnno = method.getAnnotation(HandleLog.class);//获取注解
|
|
|
if(logAnno.value() == HandleLogChoice.RECORD_ANY || logAnno.value() == HandleLogChoice.RECORD_EXCEPTION) {
|
|
if(logAnno.value() == HandleLogChoice.RECORD_ANY || logAnno.value() == HandleLogChoice.RECORD_EXCEPTION) {
|
|
|
request.setAttribute(CommonConstant.REQUEST_LOG_ATTR, handleLog);
|
|
request.setAttribute(CommonConstant.REQUEST_LOG_ATTR, handleLog);
|
|
|
request.setAttribute(CommonConstant.REQUEST_TIME_ATTR, time);
|
|
request.setAttribute(CommonConstant.REQUEST_TIME_ATTR, time);
|
|
@@ -130,10 +129,10 @@ public class HandleLogAspect {
|
|
|
Log handleLog = new Log();
|
|
Log handleLog = new Log();
|
|
|
handleLog.setId(UUIDUtil.get32UUID());
|
|
handleLog.setId(UUIDUtil.get32UUID());
|
|
|
handleLog.setCreatetime(new Date());
|
|
handleLog.setCreatetime(new Date());
|
|
|
- handleLog.setIp(request.getRemoteAddr());
|
|
|
|
|
- handleLog.setStyle(request.getMethod());
|
|
|
|
|
- handleLog.setUrl(request.getRequestURI());
|
|
|
|
|
- Map<String,String[]> paramMap = request.getParameterMap();
|
|
|
|
|
|
|
+ handleLog.setIp(request.getRemoteAddr());//获取ip地址
|
|
|
|
|
+ handleLog.setStyle(request.getMethod());//获取请求方法
|
|
|
|
|
+ handleLog.setUrl(request.getRequestURI());//获取URL
|
|
|
|
|
+ Map<String,String[]> paramMap = request.getParameterMap();//将请求转换为JSON字符串,并限制长度不能超过200字符,然后设置到日志对象中
|
|
|
if(paramMap != null&& paramMap.size() > 0) {
|
|
if(paramMap != null&& paramMap.size() > 0) {
|
|
|
String paramStr =JSONObject.toJSONString(paramMap);
|
|
String paramStr =JSONObject.toJSONString(paramMap);
|
|
|
if(paramStr.length() > 200) {
|
|
if(paramStr.length() > 200) {
|
|
@@ -141,26 +140,31 @@ public class HandleLogAspect {
|
|
|
}
|
|
}
|
|
|
handleLog.setParam(paramStr);
|
|
handleLog.setParam(paramStr);
|
|
|
}
|
|
}
|
|
|
|
|
+ //获取当前用户信息
|
|
|
User user = AccessTokenUtil.getUser();
|
|
User user = AccessTokenUtil.getUser();
|
|
|
if(user != null) {
|
|
if(user != null) {
|
|
|
handleLog.setUserid(user.getId());
|
|
handleLog.setUserid(user.getId());
|
|
|
handleLog.setUsername(user.getUsername());
|
|
handleLog.setUsername(user.getUsername());
|
|
|
}
|
|
}
|
|
|
|
|
+ //获取方法名,并设置方法全名到日志对象中
|
|
|
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
|
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
|
|
String methodName = signature.getDeclaringTypeName()+"."+signature.getName();
|
|
String methodName = signature.getDeclaringTypeName()+"."+signature.getName();
|
|
|
handleLog.setMethod(methodName);
|
|
handleLog.setMethod(methodName);
|
|
|
|
|
+ //设置模块信息,如果类上有@Tag注解,则设置模块名称到日志对象中
|
|
|
Tag tag = (Tag) signature.getDeclaringType().getDeclaredAnnotation(Tag.class);
|
|
Tag tag = (Tag) signature.getDeclaringType().getDeclaredAnnotation(Tag.class);
|
|
|
//设置模块
|
|
//设置模块
|
|
|
if(tag != null) {
|
|
if(tag != null) {
|
|
|
handleLog.setModule(tag.name());
|
|
handleLog.setModule(tag.name());
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ //如果方法上有@Operation注解,则设置操作描述到日志对象中。
|
|
|
Method method = signature.getMethod();
|
|
Method method = signature.getMethod();
|
|
|
Operation op = method.getDeclaredAnnotation(Operation.class);
|
|
Operation op = method.getDeclaredAnnotation(Operation.class);
|
|
|
//设置功能
|
|
//设置功能
|
|
|
if(op != null) {
|
|
if(op != null) {
|
|
|
handleLog.setOperation(op.summary());
|
|
handleLog.setOperation(op.summary());
|
|
|
}
|
|
}
|
|
|
|
|
+ //处理请求体中的参数,如果参数上有@RequestBody注解,则将其转换为JSON字符串,并限制长度不超过200个字符,然后设置到日志对象中。
|
|
|
Object[] args = joinPoint.getArgs();
|
|
Object[] args = joinPoint.getArgs();
|
|
|
Parameter[] params = method.getParameters();
|
|
Parameter[] params = method.getParameters();
|
|
|
for(int i=0;i<params.length;i++) {
|
|
for(int i=0;i<params.length;i++) {
|