mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-10-24 18:57:13 +08:00
perf(log): 访问日志过滤资源路径
This commit is contained in:
@@ -174,8 +174,9 @@ public abstract class AbstractLogHandler implements LogHandler {
|
|||||||
public void accessLogStart(AccessLogContext accessLogContext) {
|
public void accessLogStart(AccessLogContext accessLogContext) {
|
||||||
AccessLogProperties properties = accessLogContext.getProperties().getAccessLog();
|
AccessLogProperties properties = accessLogContext.getProperties().getAccessLog();
|
||||||
// 是否需要打印 规则: 是否打印开关 或 放行路径
|
// 是否需要打印 规则: 是否打印开关 或 放行路径
|
||||||
if (!properties.isEnabled() || accessLogContext.getProperties()
|
if (!properties.isEnabled() || AccessLogUtils.exclusionPath(accessLogContext.getProperties(), accessLogContext
|
||||||
.isMatch(accessLogContext.getRequest().getPath())) {
|
.getRequest()
|
||||||
|
.getPath())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 构建上下文
|
// 构建上下文
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ import cn.hutool.core.util.ObjectUtil;
|
|||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import top.continew.starter.log.http.RecordableHttpRequest;
|
import top.continew.starter.log.http.RecordableHttpRequest;
|
||||||
import top.continew.starter.log.model.AccessLogProperties;
|
import top.continew.starter.log.model.AccessLogProperties;
|
||||||
|
import top.continew.starter.log.model.LogProperties;
|
||||||
|
import top.continew.starter.web.util.SpringWebUtils;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -34,6 +36,12 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public class AccessLogUtils {
|
public class AccessLogUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 资源路径 - doc 路径
|
||||||
|
*/
|
||||||
|
private static final List<String> RESOURCE_PATH = List
|
||||||
|
.of("/doc/**", "/v2/api-docs/**", "/v3/api-docs/**", "/webjars/**", "/swagger-resources/**", "/swagger-ui.html");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取参数信息
|
* 获取参数信息
|
||||||
*
|
*
|
||||||
@@ -72,6 +80,19 @@ public class AccessLogUtils {
|
|||||||
return JSONUtil.toJsonStr(params);
|
return JSONUtil.toJsonStr(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排除路径
|
||||||
|
*
|
||||||
|
* @param properties 属性
|
||||||
|
* @param path 路径
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public static boolean exclusionPath(LogProperties properties, String path) {
|
||||||
|
// 放行路由配置的排除检查
|
||||||
|
return properties.isMatch(path) || RESOURCE_PATH.stream()
|
||||||
|
.anyMatch(resourcePath -> SpringWebUtils.isMatch(path, resourcePath));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 过滤敏感参数
|
* 过滤敏感参数
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user