Files
J3vbandClaude Opus 4.8 4fc21cb372 feat(server): logging & error-visibility hardening
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>
2026-07-24 11:07:12 +02:00

35 lines
1.2 KiB
Go

package db
import "log/slog"
// This file makes the secret-bearing domain types safe to log by construction.
// User.PasswordHash / User.TOTPSecret and Session.TokenHash are json:"-", but
// that only guards JSON responses — slog renders struct fields regardless. By
// implementing slog.LogValuer, logging a *db.User or *db.Session (e.g.
// slog.Info("x", "user", user)) never emits the credential. Secret fields are
// omitted entirely; the useful identifying fields stay visible.
// LogValue omits PasswordHash and TOTPSecret. It exposes whether TOTP is
// enabled (not the secret) since that is often what a log line needs.
func (u User) LogValue() slog.Value {
return slog.GroupValue(
slog.Int64("id", u.ID),
slog.String("username", u.Username),
slog.Int64("role_id", u.RoleID),
slog.String("status", u.Status),
slog.Bool("banned", u.Banned),
slog.Bool("totp_enabled", u.TOTPSecret != nil),
)
}
// LogValue omits TokenHash (the session-identifying secret).
func (s Session) LogValue() slog.Value {
return slog.GroupValue(
slog.Int64("id", s.ID),
slog.Int64("user_id", s.UserID),
slog.String("device", s.Device),
slog.String("ip", s.IP),
slog.String("expires_at", s.ExpiresAt),
)
}