feat: add slog structured logging

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
tao.chen
2026-07-02 16:34:42 +08:00
co-authored by Claude Fable 5
parent 8f2f3cf271
commit ea754a85c5
16 changed files with 1432 additions and 82 deletions
+39
View File
@@ -0,0 +1,39 @@
package logger
import (
"testing"
"codespace/pkg/config"
)
func TestNewJSONInfoLogger(t *testing.T) {
lg, err := New(config.LogConfig{Level: "info", Format: "json"})
if err != nil {
t.Fatalf("New returned error: %v", err)
}
if lg == nil {
t.Fatal("logger is nil")
}
}
func TestNewTextDebugLogger(t *testing.T) {
lg, err := New(config.LogConfig{Level: "debug", Format: "text"})
if err != nil {
t.Fatalf("New returned error: %v", err)
}
if lg == nil {
t.Fatal("logger is nil")
}
}
func TestNewRejectsInvalidLevel(t *testing.T) {
if _, err := New(config.LogConfig{Level: "verbose", Format: "json"}); err == nil {
t.Fatal("expected invalid level error")
}
}
func TestNewRejectsInvalidFormat(t *testing.T) {
if _, err := New(config.LogConfig{Level: "info", Format: "xml"}); err == nil {
t.Fatal("expected invalid format error")
}
}