mirror of https://github.com/elunez/eladmin
异步日志
parent
ec716f99f2
commit
2d19ad4915
|
@ -6,6 +6,7 @@ import me.zhengjie.exception.BadRequestException;
|
||||||
import me.zhengjie.service.LogService;
|
import me.zhengjie.service.LogService;
|
||||||
import me.zhengjie.utils.RequestHolder;
|
import me.zhengjie.utils.RequestHolder;
|
||||||
import me.zhengjie.utils.SecurityUtils;
|
import me.zhengjie.utils.SecurityUtils;
|
||||||
|
import me.zhengjie.utils.StringUtils;
|
||||||
import me.zhengjie.utils.ThrowableUtil;
|
import me.zhengjie.utils.ThrowableUtil;
|
||||||
import org.aspectj.lang.JoinPoint;
|
import org.aspectj.lang.JoinPoint;
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
|
@ -51,7 +52,7 @@ public class LogAspect {
|
||||||
currentTime = System.currentTimeMillis();
|
currentTime = System.currentTimeMillis();
|
||||||
result = joinPoint.proceed();
|
result = joinPoint.proceed();
|
||||||
Log log = new Log("INFO",System.currentTimeMillis() - currentTime);
|
Log log = new Log("INFO",System.currentTimeMillis() - currentTime);
|
||||||
logService.save(getUsername(), RequestHolder.getHttpServletRequest(),joinPoint, log);
|
logService.save(getUsername(), StringUtils.getIP(RequestHolder.getHttpServletRequest()),joinPoint, log);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +66,7 @@ public class LogAspect {
|
||||||
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);
|
||||||
log.setExceptionDetail(ThrowableUtil.getStackTrace(e));
|
log.setExceptionDetail(ThrowableUtil.getStackTrace(e));
|
||||||
logService.save(getUsername(), RequestHolder.getHttpServletRequest(), (ProceedingJoinPoint)joinPoint, log);
|
logService.save(getUsername(), StringUtils.getIP(RequestHolder.getHttpServletRequest()), (ProceedingJoinPoint)joinPoint, log);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUsername() {
|
public String getUsername() {
|
||||||
|
|
|
@ -18,7 +18,7 @@ public interface LogService {
|
||||||
* @param log
|
* @param log
|
||||||
*/
|
*/
|
||||||
@Async
|
@Async
|
||||||
void save(String username, HttpServletRequest request, ProceedingJoinPoint joinPoint, Log log);
|
void save(String username, String ip, ProceedingJoinPoint joinPoint, Log log);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询异常详情
|
* 查询异常详情
|
||||||
|
|
|
@ -5,15 +5,12 @@ import cn.hutool.json.JSONObject;
|
||||||
import me.zhengjie.domain.Log;
|
import me.zhengjie.domain.Log;
|
||||||
import me.zhengjie.repository.LogRepository;
|
import me.zhengjie.repository.LogRepository;
|
||||||
import me.zhengjie.service.LogService;
|
import me.zhengjie.service.LogService;
|
||||||
import me.zhengjie.utils.SecurityUtils;
|
|
||||||
import me.zhengjie.utils.StringUtils;
|
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
import org.aspectj.lang.reflect.MethodSignature;
|
import org.aspectj.lang.reflect.MethodSignature;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Propagation;
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,7 +28,7 @@ public class LogServiceImpl implements LogService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void save(String username, HttpServletRequest request, ProceedingJoinPoint joinPoint, Log log){
|
public void save(String username, String ip, ProceedingJoinPoint joinPoint, Log log){
|
||||||
|
|
||||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||||
Method method = signature.getMethod();
|
Method method = signature.getMethod();
|
||||||
|
@ -57,7 +54,7 @@ public class LogServiceImpl implements LogService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取IP地址
|
// 获取IP地址
|
||||||
log.setRequestIp(StringUtils.getIP(request));
|
log.setRequestIp(ip);
|
||||||
|
|
||||||
if(LOGINPATH.equals(signature.getName())){
|
if(LOGINPATH.equals(signature.getName())){
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue