Documentation ¶
Index ¶
- Variables
- func DefaultBodyLogReplacer(body []byte) []byte
- func DefaultHeaderLogReplacer(header http.Header) http.Header
- func DefaultQueryLogReplacer(query url.Values) url.Values
- func DefaultRequestBodyLogSkipper(req *http.Request) bool
- func DefaultResponseBodyLogSkipper(_ *http.Request, res *echo.Response) bool
- func Logger() echo.MiddlewareFunc
- func LoggerWithConfig(config LoggerConfig, output ...io.Writer) echo.MiddlewareFunc
- type BodyLogReplacer
- type HeaderLogReplacer
- type LoggerConfig
- type QueryLogReplacer
- type RequestBodyLogSkipper
- type ResponseBodyLogSkipper
Constants ¶
This section is empty.
Variables ¶
var ( DefaultLoggerConfig = LoggerConfig{ Skipper: middleware.DefaultSkipper, Level: zerolog.DebugLevel, LogRequestBody: false, LogRequestHeader: false, LogRequestQuery: false, RequestBodyLogSkipper: DefaultRequestBodyLogSkipper, RequestBodyLogReplacer: DefaultBodyLogReplacer, RequestHeaderLogReplacer: DefaultHeaderLogReplacer, RequestQueryLogReplacer: DefaultQueryLogReplacer, LogResponseBody: false, LogResponseHeader: false, ResponseBodyLogSkipper: DefaultResponseBodyLogSkipper, ResponseBodyLogReplacer: DefaultBodyLogReplacer, } )
Functions ¶
func DefaultBodyLogReplacer ¶
DefaultBodyLogReplacer returns the body received without any modifications.
func DefaultHeaderLogReplacer ¶
DefaultHeaderLogReplacer replaces all Authorization, X-CSRF-Token and Proxy-Authorization header entries with a redacted string, indicating their presence without revealing actual, potentially sensitive values in the logs.
func DefaultQueryLogReplacer ¶
DefaultQueryLogReplacer returns the query received without any modifications.
func DefaultRequestBodyLogSkipper ¶
DefaultRequestBodyLogSkipper returns true for all requests with Content-Type application/x-www-form-urlencoded or multipart/form-data as those might contain binary or URL-encoded file uploads unfit for logging purposes.
func DefaultResponseBodyLogSkipper ¶
DefaultResponseBodyLogSkipper returns false for all responses with Content-Type application/json, preventing logging for all other types of payloads as those might contain binary or URL-encoded data unfit for logging purposes.
func LoggerWithConfig ¶
func LoggerWithConfig(config LoggerConfig, output ...io.Writer) echo.MiddlewareFunc
LoggerWithConfig returns a new MiddlewareFunc which creates a logger with the desired configuration. If output is set to nil, the default output is used. If more output params are provided, the first is being used.
Types ¶
type BodyLogReplacer ¶
BodyLogReplacer defines a function to replace certain parts of a body before logging it, mainly used to strip sensitive information from a request or response payload. The []byte returned should contain a sanitized payload ready for logging.
type HeaderLogReplacer ¶
HeaderLogReplacer defines a function to replace certain parts of a header before logging it, mainly used to strip sensitive information from a request or response header. The http.Header returned should be a sanitized copy of the original header as not to modify the request or response while logging.
type LoggerConfig ¶
type LoggerConfig struct { Skipper middleware.Skipper Level zerolog.Level LogRequestBody bool LogRequestHeader bool LogRequestQuery bool RequestBodyLogSkipper RequestBodyLogSkipper RequestBodyLogReplacer BodyLogReplacer RequestHeaderLogReplacer HeaderLogReplacer RequestQueryLogReplacer QueryLogReplacer LogResponseBody bool LogResponseHeader bool ResponseBodyLogSkipper ResponseBodyLogSkipper ResponseBodyLogReplacer BodyLogReplacer ResponseHeaderLogReplacer HeaderLogReplacer }
type QueryLogReplacer ¶
QueryLogReplacer defines a function to replace certain parts of a URL query before logging it, mainly used to strip sensitive information from a request query. The url.Values returned should be a sanitized copy of the original query as not to modify the request while logging.
type RequestBodyLogSkipper ¶
RequestBodyLogSkipper defines a function to skip logging certain request bodies. Returning true skips logging the payload of the request.
type ResponseBodyLogSkipper ¶
ResponseBodyLogSkipper defines a function to skip logging certain response bodies. Returning true skips logging the payload of the response.