|
@@ -4,7 +4,6 @@ import cn.hutool.core.lang.Dict;
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
import cn.hutool.core.util.ArrayUtil;
|
|
import cn.hutool.core.util.ArrayUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
-import com.alibaba.ttl.TransmittableThreadLocal;
|
|
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -14,6 +13,7 @@ import org.aspectj.lang.annotation.AfterReturning;
|
|
|
import org.aspectj.lang.annotation.AfterThrowing;
|
|
import org.aspectj.lang.annotation.AfterThrowing;
|
|
|
import org.aspectj.lang.annotation.Aspect;
|
|
import org.aspectj.lang.annotation.Aspect;
|
|
|
import org.aspectj.lang.annotation.Before;
|
|
import org.aspectj.lang.annotation.Before;
|
|
|
|
|
+import org.dromara.common.core.context.ThreadLocalHolder;
|
|
|
import org.dromara.common.core.utils.ServletUtils;
|
|
import org.dromara.common.core.utils.ServletUtils;
|
|
|
import org.dromara.common.core.utils.SpringUtils;
|
|
import org.dromara.common.core.utils.SpringUtils;
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
@@ -49,9 +49,9 @@ public class LogAspect {
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 计算操作消耗时间
|
|
|
|
|
|
|
+ * 计时 key
|
|
|
*/
|
|
*/
|
|
|
- private static final ThreadLocal<StopWatch> TIME_THREADLOCAL = new TransmittableThreadLocal<>();
|
|
|
|
|
|
|
+ private static final String LOG_STOP_WATCH_KEY = "logStopwatch";
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 处理请求前执行
|
|
* 处理请求前执行
|
|
@@ -59,7 +59,7 @@ public class LogAspect {
|
|
|
@Before(value = "@annotation(controllerLog)")
|
|
@Before(value = "@annotation(controllerLog)")
|
|
|
public void boBefore(JoinPoint joinPoint, Log controllerLog) {
|
|
public void boBefore(JoinPoint joinPoint, Log controllerLog) {
|
|
|
StopWatch stopWatch = new StopWatch();
|
|
StopWatch stopWatch = new StopWatch();
|
|
|
- TIME_THREADLOCAL.set(stopWatch);
|
|
|
|
|
|
|
+ ThreadLocalHolder.set(LOG_STOP_WATCH_KEY, stopWatch);
|
|
|
stopWatch.start();
|
|
stopWatch.start();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -112,7 +112,7 @@ public class LogAspect {
|
|
|
// 处理设置注解上的参数
|
|
// 处理设置注解上的参数
|
|
|
getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult);
|
|
getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult);
|
|
|
// 设置消耗时间
|
|
// 设置消耗时间
|
|
|
- StopWatch stopWatch = TIME_THREADLOCAL.get();
|
|
|
|
|
|
|
+ StopWatch stopWatch = ThreadLocalHolder.get(LOG_STOP_WATCH_KEY);
|
|
|
stopWatch.stop();
|
|
stopWatch.stop();
|
|
|
operLog.setCostTime(stopWatch.getTime());
|
|
operLog.setCostTime(stopWatch.getTime());
|
|
|
// 发布事件保存数据库
|
|
// 发布事件保存数据库
|
|
@@ -122,7 +122,7 @@ public class LogAspect {
|
|
|
log.error("异常信息:{}", exp.getMessage());
|
|
log.error("异常信息:{}", exp.getMessage());
|
|
|
exp.printStackTrace();
|
|
exp.printStackTrace();
|
|
|
} finally {
|
|
} finally {
|
|
|
- TIME_THREADLOCAL.remove();
|
|
|
|
|
|
|
+ ThreadLocalHolder.remove(LOG_STOP_WATCH_KEY);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -161,7 +161,7 @@ public class LogAspect {
|
|
|
Map<String, String> paramsMap = ServletUtils.getParamMap(ServletUtils.getRequest());
|
|
Map<String, String> paramsMap = ServletUtils.getParamMap(ServletUtils.getRequest());
|
|
|
String requestMethod = operLog.getRequestMethod();
|
|
String requestMethod = operLog.getRequestMethod();
|
|
|
if (MapUtil.isEmpty(paramsMap)
|
|
if (MapUtil.isEmpty(paramsMap)
|
|
|
- && HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod)) {
|
|
|
|
|
|
|
+ && HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod)) {
|
|
|
String params = argsArrayToString(joinPoint.getArgs(), excludeParamNames);
|
|
String params = argsArrayToString(joinPoint.getArgs(), excludeParamNames);
|
|
|
operLog.setOperParam(StringUtils.substring(params, 0, 2000));
|
|
operLog.setOperParam(StringUtils.substring(params, 0, 2000));
|
|
|
} else {
|
|
} else {
|