This commit is contained in:
zhangzhiqiang
2023-02-09 15:00:24 +08:00
parent e395ac5803
commit c4cf28c9c1
7 changed files with 59 additions and 14 deletions

View File

@@ -0,0 +1,33 @@
package org.nl.common.utils;
/*
* @author ZZQ
* @Date 2023/2/9 2:54 下午
*/
public class BaseCode {
static final char[] MySerials = new char[]{
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p','q','r','s','t','u','v','w','x','y','z',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P','Q','R','S','T','U','V','W','X','Y','Z'};
public static final String intToChars(long n){
String s = "";
if (n == 0) {
s = "0";
}
while (n != 0) {
int i = (int) (n % MySerials.length);
char c = MySerials[i];
s = c + s;
n = n / MySerials.length;
}
for (int x = s.length();x<5;x++){
s="0"+s;
}
return s;
}
}

View File

@@ -27,6 +27,7 @@ import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.nl.common.utils.BaseCode;
import org.nl.common.utils.IdUtil;
import org.nl.common.utils.SecurityUtils;
import org.nl.modules.common.utils.RequestHolder;
@@ -67,7 +68,7 @@ public class LogAspect {
*/
@Around("@annotation(logInfo)")
public Object logAround(ProceedingJoinPoint joinPoint,org.nl.modules.logging.annotation.Log logInfo) throws Throwable {
String trackId = UUID.randomUUID().toString();
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod();
String methodName = joinPoint.getTarget().getClass().getName() + "." + signature.getName() + "()";
@@ -77,7 +78,7 @@ public class LogAspect {
MDC.put("requestMethod",methodName);
MDC.put("requestIp", StringUtils.getIp(request));
MDC.put("trackId", UUID.randomUUID().toString());
MDC.put("traceId", BaseCode.intToChars(IdUtil.getLongId()));
MDC.put("requestTime", DateUtil.now());
Object result = null;
@@ -109,20 +110,19 @@ public class LogAspect {
json.put("create_time", DateUtil.now());
Object parse = JSONObject.parse(result.toString());
json.put("return_result", parse);
log.info("请求结果:{}",parse);
interfaceLog.insert(json);
} catch (Exception e) {
}
}
}catch (Exception ex){
log.info("[--requestError--][请求方法:{}]【异常信息 :{}】", methodName, ex);
log.error("[--requestError--][请求方法:{}][请求参数:{}]【异常信息 :{}】", methodName,params, ex);
Log log = new Log("ERROR", System.currentTimeMillis() - comming);
log.setExceptionDetail(ThrowableUtil.getStackTrace(ex).getBytes());
logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request), (ProceedingJoinPoint) joinPoint, log);
throw ex;
}finally {
log.info("[--response--][请求方法:{}][请求参数:{}]【返回结果 :{}】",methodName,params,result);
log.info("[--response--][请求方法:{}][请求参数:{}],请求执行结束",methodName,params);
MDC.clear();
}
return result;
@@ -165,4 +165,7 @@ public class LogAspect {
return "";
}
}
}

View File

@@ -18,7 +18,7 @@ public class LogQuery {
/**
* 追踪id
*/
private String trackId;
private String traceId;
/**
* 日志内容模糊匹配
*/

View File

@@ -20,8 +20,9 @@ public class LogRepositoryDTO {
private String requestIp;
@Id
private String id;
private String trackId;
private String traceId;
private String requestMethod;
private String thread;
private String system;
}

View File

@@ -63,8 +63,8 @@ public class EsLogServiceImpl implements EsLogService {
if (logQuery.getFilterSql()){
query.mustNot().add(QueryBuilders.wildcardQuery("logger","org.nl.modules.wql.core.engine.*"));
}
if (StringUtils.isNotEmpty(logQuery.getTrackId())){
query.must().add(QueryBuilders.matchQuery("trackId", logQuery.getTrackId()));
if (StringUtils.isNotEmpty(logQuery.getTraceId())){
query.must().add(QueryBuilders.matchQuery("traceId", logQuery.getTraceId()));
}
if (StringUtils.isNotEmpty(logQuery.getMessage())){
query.must().add(QueryBuilders.matchQuery("message", logQuery.getMessage()).minimumShouldMatch("50%"));

View File

@@ -54,10 +54,10 @@ public class AutoCreateTask {
}
} catch (InvocationTargetException e) {
e.printStackTrace();
log.info("定时器执行失败:{}", e.getTargetException().getMessage());
log.error("定时器执行失败:{}", e.getTargetException().getMessage());
} catch (Exception e) {
e.printStackTrace();
log.info("定时器执行失败:{}", e.getMessage());
log.error("定时器执行失败:{}", e.getMessage());
}
});