Logging: structured slog messages throughout, and WithLogger options so callers choose the logger

Log messages are lower-case event names with their details as key/value
attributes ("error" for errors), in place of formatted strings.

Loggable package take a WithLogger option as part of their "New*" call,
defaulting to slog.Default(). Each tags its lines with its `component`.

Some debug loggers print directly rather than using slog when in
terminal logging mode.
This commit is contained in:
bwilliams committed 2026-10-15 16:10:52 +01:00
1 parent 0b5fde9563
commit 043e307663
49 files changed
+598 -248

No files matched your search

+3 -3
View File
@@ -22,7 +22,7 @@ func (h *Hub) ServeHTTP(w http.ResponseWriter, r *http.Request) {
CompressionMode: mode,
})
if err != nil {
h.log.Debug("upgrade failed", "error", err)
h.logger().Debug("upgrade failed", "error", err)
return // Accept has already written the HTTP error.
}
defer conn.CloseNow() //nolint:errcheck // finished with; it may already be closed
@@ -39,7 +39,7 @@ func (h *Hub) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
defer h.unregister(c)
h.log.Info("client connected", "client", c.id, "ip", ip)
h.logger().Info("client connected", "client", c.id, "ip", ip)
c.run(ctx)
h.log.Info("client disconnected", "client", c.id, "ip", ip)
h.logger().Info("client disconnected", "client", c.id, "ip", ip)
}