From 7d22178fa26d49e78fdee0c359c91c67aae6d8b3 Mon Sep 17 00:00:00 2001 From: Elune <201507802@qq.com> Date: Sat, 14 Dec 2019 12:27:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/me/zhengjie/aspect/LogAspect.java | 10 ++++++---- .../me/zhengjie/EladminSystemApplicationTests.java | 3 --- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/eladmin-logging/src/main/java/me/zhengjie/aspect/LogAspect.java b/eladmin-logging/src/main/java/me/zhengjie/aspect/LogAspect.java index a212ddf4..bf8b0a9c 100644 --- a/eladmin-logging/src/main/java/me/zhengjie/aspect/LogAspect.java +++ b/eladmin-logging/src/main/java/me/zhengjie/aspect/LogAspect.java @@ -28,7 +28,7 @@ public class LogAspect { private final LogService logService; - private long currentTime = 0L; + ThreadLocal currentTime = new ThreadLocal<>(); public LogAspect(LogService logService) { this.logService = logService; @@ -50,9 +50,10 @@ public class LogAspect { @Around("logPointcut()") public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable { Object result; - currentTime = System.currentTimeMillis(); + currentTime.set(System.currentTimeMillis()); result = joinPoint.proceed(); - Log log = new Log("INFO",System.currentTimeMillis() - currentTime); + Log log = new Log("INFO",System.currentTimeMillis() - currentTime.get()); + currentTime.remove(); HttpServletRequest request = RequestHolder.getHttpServletRequest(); logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request),joinPoint, log); return result; @@ -66,7 +67,8 @@ public class LogAspect { */ @AfterThrowing(pointcut = "logPointcut()", throwing = "e") public void logAfterThrowing(JoinPoint joinPoint, Throwable e) { - Log log = new Log("ERROR",System.currentTimeMillis() - currentTime); + Log log = new Log("ERROR",System.currentTimeMillis() - currentTime.get()); + currentTime.remove(); log.setExceptionDetail(ThrowableUtil.getStackTrace(e).getBytes()); HttpServletRequest request = RequestHolder.getHttpServletRequest(); logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request), (ProceedingJoinPoint)joinPoint, log); diff --git a/eladmin-system/src/test/java/me/zhengjie/EladminSystemApplicationTests.java b/eladmin-system/src/test/java/me/zhengjie/EladminSystemApplicationTests.java index 2b050b2b..2675a030 100644 --- a/eladmin-system/src/test/java/me/zhengjie/EladminSystemApplicationTests.java +++ b/eladmin-system/src/test/java/me/zhengjie/EladminSystemApplicationTests.java @@ -5,9 +5,6 @@ import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; -import java.util.ArrayList; -import java.util.List; - @RunWith(SpringRunner.class) @SpringBootTest public class EladminSystemApplicationTests {