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