Integrate httplog into your router (Chi, Gin, Echo, or standard http.ServeMux) using httplog.RequestLogger. It requires a *slog.Logger and an *httplog.Options configuration object.
Key configuration options in httplog.Options:
Level: Controls verbosity.slog.LevelDebug: Log all responses (including OPTIONS).slog.LevelInfo: Log responses (excluding OPTIONS).slog.LevelWarn: Log 4xx and 5xx responses only (except for 429).slog.LevelError: Log 5xx responses only.
Schema: A schema object (e.g., httplog.SchemaECS) used to format the log output via ReplaceAttr.RecoverPanics: If true, recovers from panics in handlers/middlewares, returns HTTP 500, and logs the panic as an error.Skip: A function func(req *http.Request, respStatus int) bool to filter out specific logs.LogRequestHeaders: A slice of strings specifying which request headers to log.LogResponseHeaders: A slice of strings specifying which response headers to log.LogRequestBody: A predicate function to conditionally log the request body.LogResponseBody: A predicate function to conditionally log the response body.
r.Use(httplog.RequestLogger(logger, &httplog.Options{
Level: slog.LevelInfo,
Schema: logFormat,
RecoverPanics: true,
Skip: func(req *http.Request, respStatus int) bool { return respStatus == 404 },
LogRequestHeaders: []string{"Origin"},
LogRequestBody: isDebugHeaderSet,
LogResponseBody: isDebugHeaderSet,
}))