提交 2d19ad49 编写于 作者: Z zhengjie

异步日志

上级 ec716f99
......@@ -6,6 +6,7 @@ import me.zhengjie.exception.BadRequestException;
import me.zhengjie.service.LogService;
import me.zhengjie.utils.RequestHolder;
import me.zhengjie.utils.SecurityUtils;
import me.zhengjie.utils.StringUtils;
import me.zhengjie.utils.ThrowableUtil;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
......@@ -51,7 +52,7 @@ public class LogAspect {
currentTime = System.currentTimeMillis();
result = joinPoint.proceed();
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;
}
......@@ -65,7 +66,7 @@ public class LogAspect {
public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {
Log log = new Log("ERROR",System.currentTimeMillis() - currentTime);
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() {
......
......@@ -18,7 +18,7 @@ public interface LogService {
* @param log
*/
@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.repository.LogRepository;
import me.zhengjie.service.LogService;
import me.zhengjie.utils.SecurityUtils;
import me.zhengjie.utils.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;
/**
......@@ -31,7 +28,7 @@ public class LogServiceImpl implements LogService {
@Override
@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();
Method method = signature.getMethod();
......@@ -57,7 +54,7 @@ public class LogServiceImpl implements LogService {
}
// 获取IP地址
log.setRequestIp(StringUtils.getIP(request));
log.setRequestIp(ip);
if(LOGINPATH.equals(signature.getName())){
try {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册