This commit is contained in:
zimoyin
2026-03-18 13:27:48 +08:00
parent 885b856baa
commit defe163190
7 changed files with 33 additions and 61 deletions
+8
View File
@@ -122,6 +122,14 @@ class Config
get => $this->enableVirtualCleanerParser;
}
/**
* TODO 代码内部进行数据库记录行列转换
*/
public bool $enableInternalRowColumnConvert = true {
get => $this->enableInternalRowColumnConvert;
}
private function __construct()
{
$this->detectCircularDependency();
+1 -54
View File
@@ -244,63 +244,10 @@ class LoggerIns
// 3. 添加名称前缀 [name]
$namePrefix = "<RP_NAME:{$this->name}>";
$result = $namePrefix . $processedMessage;
if ($this->isFilter()) return "";
// if ($this->isFilter()) return "";
return $result;
}
/**
* 判断当前日志是否需要过滤(核心过滤逻辑)
* @return bool true=需要过滤,false=保留日志
*/
private function isFilter(): bool
{
$logFilter = Config::getInstance()->logFilter;
// 无过滤规则时直接返回false(不过滤)
if (empty($logFilter)) {
return false;
}
// 1. 解析调用堆栈,获取业务代码的类名/方法名
$stackInfo = $this->parseBusinessStackInfo();
$className = $stackInfo['class'] ?? $this->name ?? '';
$methodName = $stackInfo['method'] ?? '';
// 2. 通配符匹配函数
$matchWildcard = function (string $pattern, string $value): bool {
// 空规则特殊处理:如:debug 拆分后类规则为空,代表匹配所有类
if ($pattern === '') {
return true;
}
// 将通配符*转换为正则的.*,并转义其他特殊字符
$regexPattern = preg_quote($pattern, '/');
$regexPattern = str_replace('\*', '.*', $regexPattern);
// 正则全程匹配
return preg_match('/^' . $regexPattern . '$/', $value) === 1;
};
// 3. 遍历过滤规则,匹配则返回true(需要过滤)
foreach ($logFilter as $filter) {
// 跳过非法过滤规则
if (!is_string($filter)) {
continue;
}
// 拆分规则为类规则和方法规则(最多拆2部分,避免方法名含:)
[$filterClassRule, $filterMethodRule] = array_pad(explode(':', $filter, 2), 2, '*');
// 匹配类名规则(支持通配符*
$isClassMatch = $matchWildcard($filterClassRule, $className);
// 匹配方法名规则(支持通配符*
$isMethodMatch = $matchWildcard($filterMethodRule, $methodName);
// 类和方法都匹配时,返回true(过滤该日志)
if ($isClassMatch && $isMethodMatch) {
return true;
}
}
// 无匹配规则,返回false(保留日志)
return false;
}
/**
* 解析调用堆栈,获取实际业务代码的类名和方法名