Documentation ¶
Overview ¶
Package chizap provides a logging and recovery middleware for chi using zap.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Get ¶
Get returns the *zap.Logger instance saved in the request context by the Logger middleware.
Must be called after the Logger middleware.
func GetSugared ¶
func GetSugared(r *http.Request) *zap.SugaredLogger
GetSugared is shorthand for:
Get(r).Sugar()
func Logger ¶
Logger returns a middleware handler that logs all requests using the passed zap.Logger.
Additionally, it saves a logger instance in the request context, to be retrieved using Get. Besides the fields already added to the logger, that instance also holds the following fields:
- request_id: the request ID, if set by github.com/go-chi/chi/v5/middleware.RequestID
- proto: the request protocol
- method: the HTTP method of the request
- path: the path of the request
- query: the query string of the request
- remote: the remote address of the client
- user_agent: the user agent of the client
- referer: the referer of the client
If you don't want a certain path prefix to be logged, you may specify it as one of the excludedPaths. Even if a path prefix is echoed, the logger will still be saved in the request context.
Types ¶
This section is empty.