Documentation
¶
Overview ¶
Package middleware provides the HTTP middlewares that log requests and record their errors.
Index ¶
- func AccessLog() func(ctx context.Context, logger *slog.Logger, r *accesslog.Record)
- func LogRequest(ctx context.Context, logger *slog.Logger, r *RequestRecord)
- func RecordError(ctx context.Context, err error)
- func SkipHuma(debug bool) func(huma.Context) bool
- func SkipRequest(debug bool) func(*http.Request) bool
- type RequestRecord
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AccessLog ¶ added in v0.2.0
AccessLog writes the access log record of a request, the one LogRequest defines, from what the accesslog middleware of huma-middleware knows about it. It is the function given to accesslog.WithRecordFunc: the record is pooled, everything is copied during the call. The error of the request (RecordError) is not read from the record: the logger the function receives is the one of the request logger, which adds the attributes of the request (the error among them) to the line.
func LogRequest ¶ added in v0.2.0
func LogRequest(ctx context.Context, logger *slog.Logger, r *RequestRecord)
LogRequest logs a request at the level of its status: server errors are errors, client errors warnings, the rest is debug. Nothing is built when the level is disabled.
func RecordError ¶ added in v0.2.0
RecordError keeps err as the error of the request: the access log reports it.
func SkipHuma ¶ added in v0.2.0
SkipHuma is the skipper of the access log for a huma operation: the monitoring endpoints are not logged, unless the debug level is on and everything is logged.
func SkipRequest ¶ added in v0.2.0
SkipRequest is SkipHuma for a plain http.Handler.
Types ¶
type RequestRecord ¶ added in v0.2.0
type RequestRecord struct {
Err error
RemoteIP string
Host string
Method string
URI string
UserAgent string
RequestID string
Latency time.Duration
Size int64
Status int
}
RequestRecord is what the request logger logs about a request. It holds no framework type, so the logging is the same whatever the router that fills it.