请求日志 异步打印
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.sqx.common.aspect;
|
||||
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import com.google.gson.Gson;
|
||||
import com.sqx.common.utils.HttpContextUtils;
|
||||
import com.sqx.common.utils.IPUtils;
|
||||
@@ -44,22 +45,27 @@ public class AppApiMethodAspect {
|
||||
|
||||
// 执行被拦截的方法
|
||||
Object result = pjp.proceed();
|
||||
|
||||
//请求的参数
|
||||
String resultJson = new Gson().toJson(result);
|
||||
try{
|
||||
HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
|
||||
long end = System.currentTimeMillis();
|
||||
if(StringUtils.isNotBlank(resultJson) && !"null".equals(resultJson)){
|
||||
log.info("\n>>>>>> {} {}\n>>>>>> IP: {} \n>>>>>> execute time:{}ms \n>>>>>> Request: {}\n>>>>>> Response: {}",
|
||||
request.getMethod(), request.getRequestURL(), IPUtils.getIpAddr(request),end-start,
|
||||
params,
|
||||
resultJson
|
||||
);
|
||||
long end = System.currentTimeMillis();
|
||||
ThreadUtil.execAsync(() -> {
|
||||
//请求的参数
|
||||
String resultJson = new Gson().toJson(result);
|
||||
try {
|
||||
HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
|
||||
if (StringUtils.isNotBlank(resultJson) && !"null".equals(resultJson)) {
|
||||
log.info("\n>>>>>> {} {}" +
|
||||
"\n>>>>>> IP: {} " +
|
||||
"\n>>>>>> execute time:{}ms " +
|
||||
"\n>>>>>> Request: {}" +
|
||||
"\n>>>>>> Response: {}",
|
||||
request.getMethod(), request.getRequestURL(), IPUtils.getIpAddr(request), end - start,
|
||||
params,
|
||||
resultJson
|
||||
);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Request 为空" + e.getMessage());
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error("Request 为空"+e.getMessage());
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user