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>
35 lines
1.2 KiB
Go
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),
|
|
)
|
|
}
|