diff --git a/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/handler/AbstractLogHandler.java b/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/handler/AbstractLogHandler.java index 2cfe6c76..9bbd8c19 100644 --- a/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/handler/AbstractLogHandler.java +++ b/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/handler/AbstractLogHandler.java @@ -174,8 +174,9 @@ public abstract class AbstractLogHandler implements LogHandler { public void accessLogStart(AccessLogContext accessLogContext) { AccessLogProperties properties = accessLogContext.getProperties().getAccessLog(); // 是否需要打印 规则: 是否打印开关 或 放行路径 - if (!properties.isEnabled() || accessLogContext.getProperties() - .isMatch(accessLogContext.getRequest().getPath())) { + if (!properties.isEnabled() || AccessLogUtils.exclusionPath(accessLogContext.getProperties(), accessLogContext + .getRequest() + .getPath())) { return; } // 构建上下文 diff --git a/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/util/AccessLogUtils.java b/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/util/AccessLogUtils.java index 010180c2..4b3164da 100644 --- a/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/util/AccessLogUtils.java +++ b/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/util/AccessLogUtils.java @@ -20,6 +20,8 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.json.JSONUtil; import top.continew.starter.log.http.RecordableHttpRequest; 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.List; @@ -34,6 +36,12 @@ import java.util.Map; */ public class AccessLogUtils { + /** + * 资源路径 - doc 路径 + */ + private static final List 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); } + /** + * 排除路径 + * + * @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)); + } + /** * 过滤敏感参数 *