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