From f2d1f3739ad06e38e77ab77c162cbc9b871ca2d4 Mon Sep 17 00:00:00 2001 From: fatedier Date: Fri, 6 Mar 2026 20:44:40 +0800 Subject: [PATCH] pkg/util/xlog: fix AddPrefix not updating existing prefix due to range value copy (#5206) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In AddPrefix, the loop `for _, p := range l.prefixes` creates a copy of each element. Assignments to p.Value and p.Priority only modify the local copy, not the original slice element, causing updates to existing prefixes to be silently lost. This affects client/service.go where AddPrefix is called with Name:"runID" on reconnection — the old runID value would persist in log output instead of being updated to the new one. Fix by using index-based access `l.prefixes[i]` to modify the original slice element, and add break since prefix names are unique. --- pkg/util/xlog/xlog.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/util/xlog/xlog.go b/pkg/util/xlog/xlog.go index a1a58d42..f8f4116a 100644 --- a/pkg/util/xlog/xlog.go +++ b/pkg/util/xlog/xlog.go @@ -63,11 +63,12 @@ func (l *Logger) AddPrefix(prefix LogPrefix) *Logger { if prefix.Priority <= 0 { prefix.Priority = 10 } - for _, p := range l.prefixes { + for i, p := range l.prefixes { if p.Name == prefix.Name { found = true - p.Value = prefix.Value - p.Priority = prefix.Priority + l.prefixes[i].Value = prefix.Value + l.prefixes[i].Priority = prefix.Priority + break } } if !found {