This commit is contained in:
zhangzq
2025-01-15 22:18:47 +08:00
parent 85937ab49f
commit 47edc84ecc
2 changed files with 27 additions and 12 deletions

View File

@@ -1,11 +1,19 @@
package org.nl.config; package org.nl.config;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import com.yomahub.tlog.id.TLogIdGenerator; import com.yomahub.tlog.id.TLogIdGenerator;
import java.util.UUID;
public class TlogIdGenerator extends TLogIdGenerator { public class TlogIdGenerator extends TLogIdGenerator {
@Override @Override
public String generateTraceId() { public String generateTraceId() {
return IdUtil.getSnowflake(1, 1).nextIdStr(); String idStr = String.valueOf(System.currentTimeMillis());
try {
idStr = IdUtil.getSnowflake(1, 1).nextIdStr();
}catch (Exception ex){
}
return idStr;
} }
} }

View File

@@ -16,6 +16,7 @@ import org.nl.system.service.logging.ISysInterfaceLogService;
import org.nl.system.service.logging.dao.SysInterfaceLog; import org.nl.system.service.logging.dao.SysInterfaceLog;
import org.nl.system.service.logging.dao.SysLog; import org.nl.system.service.logging.dao.SysLog;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.AntPathMatcher; import org.springframework.util.AntPathMatcher;
import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.RequestContextHolder;
@@ -37,8 +38,8 @@ import java.util.stream.Collectors;
* @Date: 2024/7/25 15:06 * @Date: 2024/7/25 15:06
*/ */
@Slf4j @Slf4j
//@Aspect @Aspect
//@Component @Component
public class WhiteListLogAspect { public class WhiteListLogAspect {
@Autowired @Autowired
@@ -54,13 +55,12 @@ public class WhiteListLogAspect {
// 该方法无方法体,主要为了让同类中其他方法使用此切入点 // 该方法无方法体,主要为了让同类中其他方法使用此切入点
} }
// @Around("logPointcut()") @Around("logPointcut()")
public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable { public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
Object[] args = joinPoint.getArgs(); Object[] args = joinPoint.getArgs();
Object result = null; long startTime = System.currentTimeMillis();
try { try {
long startTime = System.currentTimeMillis(); Object result = joinPoint.proceed(args);
result = joinPoint.proceed(args);
long endTime = System.currentTimeMillis(); long endTime = System.currentTimeMillis();
long time = endTime - startTime; long time = endTime - startTime;
MethodSignature signature = (MethodSignature) joinPoint.getSignature(); MethodSignature signature = (MethodSignature) joinPoint.getSignature();
@@ -68,10 +68,12 @@ public class WhiteListLogAspect {
if (!shouldLog(signature.getName())){ if (!shouldLog(signature.getName())){
addLog(joinPoint, JSONUtil.toJsonStr(result), time); addLog(joinPoint, JSONUtil.toJsonStr(result), time);
} }
return result;
} catch (Exception e) { } catch (Exception e) {
log.error("doAround日志记录异常异常信息为:", e); log.error("doAround日志记录异常异常信息为:", e);
throw e;
} }
return result;
} }
/** /**
@@ -100,10 +102,15 @@ public class WhiteListLogAspect {
@AfterThrowing(pointcut = "logPointcut()", throwing = "e") @AfterThrowing(pointcut = "logPointcut()", throwing = "e")
public void logAfterThrowing(JoinPoint joinPoint, Throwable e) { public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {
SysInterfaceLog log = new SysInterfaceLog("ERROR", 0L); try {
log.setException_detail(ThrowableUtil.getStackTrace(e).getBytes()); SysInterfaceLog log = new SysInterfaceLog("ERROR", 0L);
HttpServletRequest request = RequestHolder.getHttpServletRequest(); log.setException_detail(ThrowableUtil.getStackTrace(e).getBytes());
interfaceLogService.save(getUsername(), e.toString(), StringUtils.getBrowser(request), StringUtils.getIp(request), (ProceedingJoinPoint) joinPoint, log); HttpServletRequest request = RequestHolder.getHttpServletRequest();
interfaceLogService.save(getUsername(), e.toString(), StringUtils.getBrowser(request), StringUtils.getIp(request), (ProceedingJoinPoint) joinPoint, log);
}catch (Exception ex){
log.error("doAround日志记录异常异常信息为:", ex);
}
} }
/** /**