Documentation
¶
Overview ¶
Package logutil configures structured JSON logging on log/slog and provides the HTTP request-logging middleware. gogo logs only through slog; there is no fmt.Print logging anywhere in the tree (NFR-10).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RequestLogger ¶
func RequestLogger(clientIP ClientIPFunc, next http.Handler) http.Handler
RequestLogger logs one JSON line per request at debug level for /healthz and /metrics (which a scraper hits constantly) and at info level otherwise.
It records two addresses, because behind a proxy they differ and both matter: `remote` is the resolved client, which is what an abuse report is about, and `peer` is the immediate connection, which is the proxy.
func Setup ¶
func Setup(level slog.Level, count RecordFunc) *slog.Logger
Setup installs a JSON slog handler on stdout at the given level and makes it the process default. It returns the logger for callers that prefer to pass it around.
count may be nil. When it is not, it is called once per emitted record, which is what puts a log rate on a dashboard: a handler below the configured level is never reached, so what is counted is what was written.
func Wrap ¶
func Wrap(w http.ResponseWriter) interface { http.ResponseWriter Status() int Bytes() int64 }
Wrap returns a ResponseWriter that records the status and byte count.
Types ¶
type ClientIPFunc ¶
ClientIPFunc resolves the address of the real client behind any trusted reverse proxy. auth.ClientIP provides the implementation; taking it as a function keeps logutil free of dependencies, and of an import cycle.
type RecordFunc ¶ added in v1.25.0
type RecordFunc func(level string)
RecordFunc is told the severity of each record actually written -- "debug", "info", "warn" or "error". metrics.LogRecord is the implementation gogo.Run passes; taking it as a function keeps logutil free of a dependency on metrics, which imports logutil itself.