feat(logging): integrate slog logging with env control and request/sync tracing
MindSift CI & Docker Release / Build, Test in Container & Push (push) Successful in 39s
MindSift CI & Docker Release / Build, Test in Container & Push (push) Successful in 39s
- Configure structured slog logger in cmd/server/main.go via LOG_LEVEL and DEBUG env vars - Add HTTP API request logging middleware in internal/api/ with status and duration_ms - Add WebSocket join/leave, event reception, and debounced SQLite flush tracing in docroom - Document LOG_LEVEL and DEBUG settings in .env.example, compose.yaml, and docker-compose.yml
This commit is contained in:
1 parent
177e24fdc8
commit
48fe61fbce
9 files changed
+208
-16
No files matched your search
@@ -0,0 +1,58 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestConfigLogLevelAndDebug(t *testing.T) {
|
||||
os.Setenv("PORT", "9090")
|
||||
defer os.Unsetenv("PORT")
|
||||
|
||||
// 1. Default info
|
||||
os.Unsetenv("LOG_LEVEL")
|
||||
os.Unsetenv("DEBUG")
|
||||
cfg := Load()
|
||||
if cfg.SlogLevel() != slog.LevelInfo {
|
||||
t.Fatalf("expected LevelInfo, got %v", cfg.SlogLevel())
|
||||
}
|
||||
|
||||
// 2. LOG_LEVEL=debug
|
||||
os.Setenv("LOG_LEVEL", "debug")
|
||||
cfg = Load()
|
||||
if cfg.SlogLevel() != slog.LevelDebug {
|
||||
t.Fatalf("expected LevelDebug, got %v", cfg.SlogLevel())
|
||||
}
|
||||
|
||||
// 3. LOG_LEVEL=warn
|
||||
os.Setenv("LOG_LEVEL", "warn")
|
||||
cfg = Load()
|
||||
if cfg.SlogLevel() != slog.LevelWarn {
|
||||
t.Fatalf("expected LevelWarn, got %v", cfg.SlogLevel())
|
||||
}
|
||||
|
||||
// 4. LOG_LEVEL=error
|
||||
os.Setenv("LOG_LEVEL", "error")
|
||||
cfg = Load()
|
||||
if cfg.SlogLevel() != slog.LevelError {
|
||||
t.Fatalf("expected LevelError, got %v", cfg.SlogLevel())
|
||||
}
|
||||
|
||||
// 5. DEBUG=true overrides LOG_LEVEL
|
||||
os.Setenv("LOG_LEVEL", "error")
|
||||
os.Setenv("DEBUG", "true")
|
||||
cfg = Load()
|
||||
if cfg.SlogLevel() != slog.LevelDebug {
|
||||
t.Fatalf("expected LevelDebug when DEBUG=true, got %v", cfg.SlogLevel())
|
||||
}
|
||||
|
||||
// 6. DEBUG=1 overrides LOG_LEVEL
|
||||
os.Setenv("DEBUG", "1")
|
||||
cfg = Load()
|
||||
if cfg.SlogLevel() != slog.LevelDebug {
|
||||
t.Fatalf("expected LevelDebug when DEBUG=1, got %v", cfg.SlogLevel())
|
||||
}
|
||||
os.Unsetenv("DEBUG")
|
||||
os.Unsetenv("LOG_LEVEL")
|
||||
}
|
||||
Reference in new issue
Block a user