Documentation
¶
Overview ¶
Package loggerext provides an extension of "github.com/xgfone/go-apiserver/http/middleware/logger" to support to log the request and response header and body.
Usage ¶
import ( loggerext "github.com/xgfone/go-apiserver-middleware-logger-ext" "github.com/xgfone/go-apiserver/http/router" ) router.DefaultRouter.Middlewares.InsertFunc(loggerext.WrapHandler)
Index ¶
- func AppendIgnorePath(path string)
- func Collect(w http.ResponseWriter, r *http.Request, appendAttr func(...slog.Attr))
- func DisableLogRespBody(ctx context.Context) context.Context
- func Enabled(req *http.Request) bool
- func Release(w http.ResponseWriter, r *http.Request)
- func WrapHandler(next http.Handler) http.Handler
- func WrapReqRespBody(w http.ResponseWriter, r *http.Request) (http.ResponseWriter, *http.Request)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendIgnorePath ¶ added in v0.5.0
func AppendIgnorePath(path string)
AppendIgnorePath appends the ignored path, which is not logged.
"" and "/" are ignored. If path ends with "/", it is a prefix matching; Or, an equal matching.
func Collect ¶ added in v0.2.0
Collect collects the key-value log information and appends them by appendAttr.
func DisableLogRespBody ¶ added in v0.3.0
DisableLogRespBody returns a new context to set a flag to indicate not to log the response body.
If not set, use the default policy.
func Release ¶ added in v0.2.0
func Release(w http.ResponseWriter, r *http.Request)
Release tries to release the buffer into the pool.
func WrapHandler ¶ added in v0.2.0
WrapHandler wraps a http handler and returns a new, which will replace the request and response writer, so must be used before the logger middleware.
func WrapReqRespBody ¶ added in v0.2.0
func WrapReqRespBody(w http.ResponseWriter, r *http.Request) (http.ResponseWriter, *http.Request)
WrapReqRespBody wraps the http request and response writer, and returns the new, which is used by the http middleware, such as WrapHandler.
NOTICE: Release should be called after handling the request.
Types ¶
This section is empty.