Documentation
¶
Overview ¶
Package logger implements logging middleware
Index ¶
- func AnonymizeIP(ip string) string
- func ApacheCombined(l *Middleware)
- func Logger(next http.Handler) http.Handler
- func WithBody(l *Middleware)
- type Backend
- type Middleware
- type Option
- func BodyFn(bodyFn func(body string, truncated bool) string) Option
- func IPfn(ipFn func(ip string) string) Option
- func Log(log Backend) Option
- func MaxBodySize(maximum int) Option
- func Prefix(prefix string) Option
- func SubjFn(subjFn func(r *http.Request) (string, error)) Option
- func UserFn(userFn func(r *http.Request) (string, error)) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnonymizeIP ¶ added in v1.5.4
AnonymizeIP resets the last part of IPv4 to 0 and the low 80 bits of IPv6 to 0, keeping the /48 network: 123.212.12.78 becomes 123.212.12.0, 2001:db8:abcd:12::1 becomes 2001:db8:abcd::. An IPv4 address in IPv6 form keeps its form, ::ffff:808:404 becomes ::ffff:8.8.4.0. A port, square brackets and an IPv6 zone are dropped. A value that is not an IP address is reset after its last dot if it has four dot-separated parts, otherwise returned unchanged.
func ApacheCombined ¶ added in v1.5.4
func ApacheCombined(l *Middleware)
ApacheCombined sets format to Apache Combined Log. See http://httpd.apache.org/docs/2.2/logs.html#combined
func WithBody ¶ added in v1.4.0
func WithBody(l *Middleware)
WithBody triggers request body logging. Body size is limited (default 1k)
Types ¶
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware is a logger for rest requests.
type Option ¶
type Option func(l *Middleware)
Option func type
func BodyFn ¶ added in v1.23.0
BodyFn sets a transform applied to the request body before it is logged, e.g. to mask secrets. It only runs when body logging is enabled (see WithBody) and the body is non-empty; if bodyFn is nil the body is logged unchanged. bodyFn receives the body (capped at MaxBodySize) and a truncated flag that is true when the body was longer than MaxBodySize and got cut short - a masker can use it to emit a marker instead of risking a pass-through of a partial body it cannot parse. The returned string is what gets logged, so bodyFn owns the content; the logger still collapses it to a single line to keep one log record per request.
func MaxBodySize ¶
MaxBodySize sets size of the logged part of the request body.