feat(log): 访问日志携带 ua,挂 Seq 后控制台放宽到 Info+

- WebConnectLog 访问日志新增 ua 字段(User-Agent 按 rune 截断 200 字符),便于按设备归因
- SetSeqWriter 挂 Seq 后业务控制台由 Warn+ 放宽为 Info+,Debug/SQL 仍只进 Seq 与文件
- 新增 Logger.SetConsoleMinLevel,访问日志控制台单独保持 Warn+

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-24 01:35:45 +08:00
parent 853940c795
commit 332c2414bc
6 changed files with 180 additions and 11 deletions
+15 -6
View File
@@ -209,6 +209,8 @@ func TestLevelFilterWriter_WarnOnly(t *testing.T) {
}
}
// TestSetSeqWriter_QuietsConsoleKeepsSeqFull 验证挂 Seq 后控制台放宽到 Info+:
// Debug 不上控制台,Info/Warn 均可见,Seq 侧全量收到(含 Debug)。
func TestSetSeqWriter_QuietsConsoleKeepsSeqFull(t *testing.T) {
var mu sync.Mutex
var gotBody string
@@ -223,13 +225,14 @@ func TestSetSeqWriter_QuietsConsoleKeepsSeqFull(t *testing.T) {
consoleBuf := &captureBuf{}
l.console.inner = consoleBuf
l.SetSeqWriter(srv.URL, "", "test:quiet")
l.Info().Msg("info-to-seq-only")
l.Debug().Msg("debug-to-seq-only")
l.Info().Msg("info-both")
l.Warn().Msg("warn-both")
deadline := time.Now().Add(3 * time.Second)
for time.Now().Before(deadline) {
mu.Lock()
ok := strings.Contains(gotBody, "info-to-seq-only") && strings.Contains(gotBody, "warn-both")
ok := strings.Contains(gotBody, "debug-to-seq-only") && strings.Contains(gotBody, "info-both") && strings.Contains(gotBody, "warn-both")
mu.Unlock()
if ok {
break
@@ -239,22 +242,28 @@ func TestSetSeqWriter_QuietsConsoleKeepsSeqFull(t *testing.T) {
mu.Lock()
body := gotBody
mu.Unlock()
if !strings.Contains(body, "info-to-seq-only") || !strings.Contains(body, "warn-both") {
if !strings.Contains(body, "debug-to-seq-only") || !strings.Contains(body, "info-both") || !strings.Contains(body, "warn-both") {
t.Fatalf("Seq incomplete: %q", body)
}
consoleBuf.mu.Lock()
defer consoleBuf.mu.Unlock()
for _, line := range consoleBuf.lines {
if strings.Contains(line, "info-to-seq-only") {
t.Fatalf("Info leaked to console: %v", consoleBuf.lines)
if strings.Contains(line, "debug-to-seq-only") {
t.Fatalf("Debug leaked to console: %v", consoleBuf.lines)
}
}
foundWarn := false
foundInfo, foundWarn := false, false
for _, line := range consoleBuf.lines {
if strings.Contains(line, "info-both") {
foundInfo = true
}
if strings.Contains(line, "warn-both") {
foundWarn = true
}
}
if !foundInfo {
t.Fatalf("Info missing on console: %v", consoleBuf.lines)
}
if !foundWarn {
t.Fatalf("Warn missing on console: %v", consoleBuf.lines)
}