From 54ca40bbcd843a605a9c3c7668dde72171e952dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=98=AD?= <81747598+lan-yonghui@users.noreply.github.com> Date: Thu, 10 Jul 2025 11:21:13 +0800 Subject: [PATCH] fix: Fix container log download ANSI control code garbled issue (#9479) --- agent/app/service/container.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/agent/app/service/container.go b/agent/app/service/container.go index f7ea6114c..d4f85d712 100644 --- a/agent/app/service/container.go +++ b/agent/app/service/container.go @@ -12,6 +12,7 @@ import ( "os" "os/exec" "path/filepath" + "regexp" "sort" "strconv" "strings" @@ -1064,9 +1065,11 @@ func (u *ContainerService) DownloadContainerLogs(containerType, container, since errCh := make(chan error) go func() { scanner := bufio.NewScanner(stdout) + var ansiRegex = regexp.MustCompile(`\x1b\[[0-9;?]*[A-Za-z]|\x1b=|\x1b>`) for scanner.Scan() { line := scanner.Text() - if _, err := tempFile.WriteString(line + "\n"); err != nil { + cleanLine := ansiRegex.ReplaceAllString(line, "") + if _, err := tempFile.WriteString(cleanLine + "\n"); err != nil { errCh <- err return }