feat(logger): WithSource/Scoped 日志来源标注;AGENTS 追加日志标来源+客户端API契约红线

This commit is contained in:
Aska committed 2026-09-06 05:22:00 +08:00
1 parent be67d74822
commit 10c0069fa7
3 files changed
+48

No files matched your search

+25
View File
@@ -91,3 +91,28 @@ func TestNew_DefaultsToErrAndText(t *testing.T) {
t.Fatal("New(Options{}) returned nil logger")
}
}
func TestWithSource_TagsRecords(t *testing.T) {
t.Parallel()
var buf bytes.Buffer
base := New(Options{Level: "debug", Format: "json", Out: &buf})
log := WithSource(base, "runtime/loop")
log.Info("hello")
if !strings.Contains(buf.String(), `"source":"runtime/loop"`) {
t.Fatalf("missing source field, got %q", buf.String())
}
}
func TestScoped_TagsModuleAndSub(t *testing.T) {
t.Parallel()
var buf bytes.Buffer
base := New(Options{Level: "debug", Format: "json", Out: &buf})
log := Scoped(base, "channel", "adapter")
log.Info("hello")
got := buf.String()
if !strings.Contains(got, `"module":"channel"`) || !strings.Contains(got, `"sub":"adapter"`) {
t.Fatalf("missing module/sub fields, got %q", got)
}
}