fix:新增打印黑名单,以及定时器日志打印
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package org.nl.modules.logging.aspect;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
@@ -62,7 +63,11 @@ public class WhiteListLogAspect {
|
||||
result = joinPoint.proceed(args);
|
||||
long endTime = System.currentTimeMillis();
|
||||
long time = endTime - startTime;
|
||||
addLog(joinPoint, JSONUtil.toJsonStr(result), time);
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
//黑名单接口不打印日志
|
||||
if (!shouldLog(signature.getName())){
|
||||
addLog(joinPoint, JSONUtil.toJsonStr(result), time);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("doAround日志记录异常,异常信息为:", e);
|
||||
throw e;
|
||||
@@ -75,39 +80,15 @@ public class WhiteListLogAspect {
|
||||
*/
|
||||
public void addLog(ProceedingJoinPoint joinPoint, String outParams, long time) {
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
HttpServletResponse response = attributes.getResponse();
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
Method method = signature.getMethod();
|
||||
HttpServletRequest request = null;
|
||||
if (ObjectUtil.isNotEmpty(attributes)) {
|
||||
request = attributes.getRequest();
|
||||
}
|
||||
// 方法路径
|
||||
String methodName = joinPoint.getTarget().getClass().getName() + "." + signature.getName() + "()";
|
||||
String[] split = joinPoint.getTarget().getClass().getName().split("\\.");
|
||||
String className = split[split.length - 1];
|
||||
StringUtils.getIp(request);
|
||||
log.info("\n\r=======================================\n\r" +
|
||||
"请求地址:{} \n\r" +
|
||||
"请求方式:{} \n\r" +
|
||||
"请求类方法:{} \n\r" +
|
||||
"方法名::{} \n\r" +
|
||||
"调用IP::{} \n\r" +
|
||||
"接口名称:{} \n\r" +
|
||||
"请求方法参数:{} \n\r" +
|
||||
"返回报文:{} \n\r" +
|
||||
"处理耗时:{} ms \n\r" +
|
||||
"=======================================\n\r",
|
||||
request.getRequestURI(),
|
||||
request.getMethod(),
|
||||
joinPoint.getSignature(),
|
||||
className,
|
||||
StringUtils.getIp(request),
|
||||
signature.getName(),
|
||||
JSONUtil.toJsonStr(filterArgs(joinPoint.getArgs())),
|
||||
outParams,
|
||||
time
|
||||
);
|
||||
SysInterfaceLog log = new SysInterfaceLog("INFO", time);
|
||||
|
||||
interfaceLogService.save(getUsername(), outParams, StringUtils.getBrowser(request), StringUtils.getIp(request), joinPoint, log);
|
||||
String borwser = ObjectUtil.isNotEmpty(attributes) ? StringUtils.getBrowser(request) : "定时器";
|
||||
String ip = ObjectUtil.isNotEmpty(attributes) ? StringUtils.getIp(request) : "定时器";
|
||||
interfaceLogService.save(getUsername(), outParams, borwser, ip, joinPoint, log);
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
@@ -138,5 +119,9 @@ public class WhiteListLogAspect {
|
||||
&& !(object instanceof HttpServletResponse)
|
||||
).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private boolean shouldLog(String requestURI) {
|
||||
return loggingProperties.getIncludePaths().stream().anyMatch(pattern -> pathMatcher.match(pattern, requestURI));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,8 +39,6 @@ public class SysInterfaceLogServiceImpl extends ServiceImpl<SysInterfaceLogMappe
|
||||
@Override
|
||||
public void save(String username, String outParam, String browser, String ip, ProceedingJoinPoint joinPoint, SysInterfaceLog logDto) {
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
Method method = signature.getMethod();
|
||||
|
||||
|
||||
String[] split = joinPoint.getTarget().getClass().getName().split("\\.");
|
||||
String className = split[split.length - 1];
|
||||
|
||||
@@ -92,11 +92,9 @@ logging:
|
||||
file:
|
||||
path: d:\log\lms
|
||||
config: classpath:logback-spring.xml
|
||||
#接口日志黑名单
|
||||
include-paths:
|
||||
- /api/mes/**
|
||||
- /api/lms/**
|
||||
- /api/sap/**
|
||||
- /api/crm/**
|
||||
- getHotPointStatus
|
||||
# sa-token白名单配置
|
||||
security:
|
||||
# 排除路径
|
||||
|
||||
Reference in New Issue
Block a user