请求日志添加 traceId
This commit is contained in:
@@ -11,10 +11,13 @@ import org.aspectj.lang.ProceedingJoinPoint;
|
|||||||
import org.aspectj.lang.annotation.Around;
|
import org.aspectj.lang.annotation.Around;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
import org.aspectj.lang.annotation.Pointcut;
|
import org.aspectj.lang.annotation.Pointcut;
|
||||||
|
import org.slf4j.MDC;
|
||||||
import org.springframework.context.annotation.Profile;
|
import org.springframework.context.annotation.Profile;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 方法调用统一切面处理
|
* 方法调用统一切面处理
|
||||||
@@ -59,7 +62,13 @@ public class ControllerAspect {
|
|||||||
String requestUrl = request.getRequestURL().toString();
|
String requestUrl = request.getRequestURL().toString();
|
||||||
String requestIp = ServletUtil.getClientIP(request);
|
String requestIp = ServletUtil.getClientIP(request);
|
||||||
long useTime = end - start;
|
long useTime = end - start;
|
||||||
|
|
||||||
|
Map<String, String> contextMap = MDC.getCopyOfContextMap();
|
||||||
ThreadUtil.execAsync(() -> {
|
ThreadUtil.execAsync(() -> {
|
||||||
|
if (contextMap != null) {
|
||||||
|
MDC.setContextMap(contextMap);
|
||||||
|
}
|
||||||
|
|
||||||
//请求的参数
|
//请求的参数
|
||||||
String resultJson = JSONObject.toJSONString(result);
|
String resultJson = JSONObject.toJSONString(result);
|
||||||
if (StrUtil.isNotBlank(resultJson) && resultJson.length() > 200) {
|
if (StrUtil.isNotBlank(resultJson) && resultJson.length() > 200) {
|
||||||
@@ -82,6 +91,8 @@ public class ControllerAspect {
|
|||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Request 为空" + e.getMessage());
|
log.error("Request 为空" + e.getMessage());
|
||||||
|
} finally {
|
||||||
|
MDC.clear();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
Reference in New Issue
Block a user