Commit 7d22178f authored by Elune's avatar Elune
Browse files

代码优化

parent ebdf7799
...@@ -28,7 +28,7 @@ public class LogAspect { ...@@ -28,7 +28,7 @@ public class LogAspect {
private final LogService logService; private final LogService logService;
private long currentTime = 0L; ThreadLocal<Long> currentTime = new ThreadLocal<>();
public LogAspect(LogService logService) { public LogAspect(LogService logService) {
this.logService = logService; this.logService = logService;
...@@ -50,9 +50,10 @@ public class LogAspect { ...@@ -50,9 +50,10 @@ public class LogAspect {
@Around("logPointcut()") @Around("logPointcut()")
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable { public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
Object result; Object result;
currentTime = System.currentTimeMillis(); currentTime.set(System.currentTimeMillis());
result = joinPoint.proceed(); 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(); HttpServletRequest request = RequestHolder.getHttpServletRequest();
logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request),joinPoint, log); logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request),joinPoint, log);
return result; return result;
...@@ -66,7 +67,8 @@ public class LogAspect { ...@@ -66,7 +67,8 @@ public class LogAspect {
*/ */
@AfterThrowing(pointcut = "logPointcut()", throwing = "e") @AfterThrowing(pointcut = "logPointcut()", throwing = "e")
public void logAfterThrowing(JoinPoint joinPoint, Throwable 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()); log.setExceptionDetail(ThrowableUtil.getStackTrace(e).getBytes());
HttpServletRequest request = RequestHolder.getHttpServletRequest(); HttpServletRequest request = RequestHolder.getHttpServletRequest();
logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request), (ProceedingJoinPoint)joinPoint, log); logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request), (ProceedingJoinPoint)joinPoint, log);
......
...@@ -5,9 +5,6 @@ import org.junit.runner.RunWith; ...@@ -5,9 +5,6 @@ import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import java.util.ArrayList;
import java.util.List;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest @SpringBootTest
public class EladminSystemApplicationTests { public class EladminSystemApplicationTests {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment