过滤无价值日志并实现最近24小时倒序分页查询
Security Checks / security (push) Waiting to run

This commit is contained in:
xuans committed 2026-09-09 01:06:45 +08:00
1 parent 161bc3a345
commit bb4ac4d5f5
20 files changed
+765 -132

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
package config
import (
"errors"
"runtime"
"strings"
"testing"
"time"
log "github.com/sirupsen/logrus"
)
func TestLogFormatterPreservesStructuredEvidence(t *testing.T) {
formatter := &logFormatter{}
for _, message := range []string{"", "连接失败"} {
entry := &log.Entry{
Time: time.Now(), Level: log.InfoLevel, Message: message,
Caller: &runtime.Frame{File: "test.go", Line: 12},
Data: log.Fields{"error": errors.New("测试错误\n下一行"), "code": 0, "unsupported": make(chan int)},
}
data, err := formatter.Format(entry)
if err != nil {
t.Fatal(err)
}
text := string(data)
for _, expected := range []string{`"error":"测试错误\n下一行"`, `"code":0`, "无法序列化的字段", message} {
if !strings.Contains(text, expected) {
t.Fatalf("字段丢失:%s", text)
}
}
if strings.Count(text, "\n") != 1 {
t.Fatal("结构化错误中的换行不应生成伪记录")
}
}
}