mirror of https://github.com/elunez/eladmin
代码优化
parent
ebdf7799ca
commit
7d22178fa2
|
@ -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 {
|
||||||
@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 {
|
||||||
*/
|
*/
|
||||||
@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;
|
||||||
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 {
|
||||||
|
|
Loading…
Reference in New Issue