mirror of
https://github.com/J3vb/OwnCord.git
synced 2026-09-03 03:50:00 +03:00
Make server failures debuggable without leaking secrets: - configurable stdout log level (config.yaml logging.level + OWNCORD_LOGGING_LEVEL) - preserve the DB cause in ErrInternal wraps; log auth-DB failures distinctly from bad tokens; log the previously-silent expired-session cleanup goroutine - route HTTP handler panics through slog (was chi stderr-only, invisible to the admin log stream) - stackutil: argument-free panic stacks so key/token bytes never reach the admin ring buffer / SSE; slog.LogValuer redaction on VoiceConfig/GitHubConfig/ GIFConfig/Config and db.User/db.Session - logctx: req_id/trace_id correlation on ...Context log calls Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package config
|
|
|
|
import (
|
|
"log/slog"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestParseLevel(t *testing.T) {
|
|
cases := []struct {
|
|
in string
|
|
want slog.Level
|
|
ok bool
|
|
}{
|
|
{"debug", slog.LevelDebug, true},
|
|
{"info", slog.LevelInfo, true},
|
|
{"", slog.LevelInfo, true},
|
|
{"WARN", slog.LevelWarn, true},
|
|
{"warning", slog.LevelWarn, true},
|
|
{"error", slog.LevelError, true},
|
|
{" Debug ", slog.LevelDebug, true},
|
|
{"bogus", slog.LevelInfo, false},
|
|
}
|
|
for _, c := range cases {
|
|
got, ok := ParseLevel(c.in)
|
|
if got != c.want || ok != c.ok {
|
|
t.Errorf("ParseLevel(%q) = %v,%v want %v,%v", c.in, got, ok, c.want, c.ok)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestLoggingLevelFromEnv verifies the end-to-end wiring: OWNCORD_LOGGING_LEVEL
|
|
// overrides config.yaml via koanf's existing env layer.
|
|
func TestLoggingLevelFromEnv(t *testing.T) {
|
|
cfgPath := filepath.Join(t.TempDir(), "config.yaml")
|
|
t.Setenv("OWNCORD_LOGGING_LEVEL", "debug")
|
|
|
|
cfg, err := Load(cfgPath)
|
|
if err != nil {
|
|
t.Fatalf("Load: %v", err)
|
|
}
|
|
if cfg.Logging.Level != "debug" {
|
|
t.Errorf("expected level %q from env, got %q", "debug", cfg.Logging.Level)
|
|
}
|
|
if lvl, ok := ParseLevel(cfg.Logging.Level); !ok || lvl != slog.LevelDebug {
|
|
t.Errorf("ParseLevel(%q) = %v,%v", cfg.Logging.Level, lvl, ok)
|
|
}
|
|
}
|