From 7cf767cbaa415baf2ba1537ceb4451ef33aee347 Mon Sep 17 00:00:00 2001 From: ideaa Date: Mon, 29 Sep 2025 15:58:56 +0800 Subject: [PATCH] fix(logger): make action pattern matching case-insensitive and simplify filter logic Remove case sensitivity check in action pattern matching and eliminate redundant string contains check since pattern matching already covers this --- logger/zap.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/logger/zap.go b/logger/zap.go index f798f74..c4adfc8 100644 --- a/logger/zap.go +++ b/logger/zap.go @@ -137,7 +137,7 @@ func getFileStyleEncoder(c config.Logger) zapcore.Encoder { continue } - patternStr := fmt.Sprintf(`"action"\s*:\s*"%s"`, regexp.QuoteMeta(actionPattern)) + patternStr := fmt.Sprintf(`(?i)"action":"%s"`, regexp.QuoteMeta(actionPattern)) pattern := regexp.MustCompile(patternStr) filters = append(filters, FilterRule{ @@ -250,7 +250,7 @@ func (e *fileStyleEncoder) EncodeEntry(entry zapcore.Entry, fields []zapcore.Fie func (e *fileStyleEncoder) processMessage(msg string, filters []FilterRule) string { for _, rule := range filters { - if strings.Contains(msg, rule.Action) && rule.Pattern.MatchString(msg) { + if rule.Pattern.MatchString(msg) { // 查找字段位置 fieldKey := fmt.Sprintf(`"%s":`, rule.Field) pos := strings.Index(msg, fieldKey)