Documentation
¶
Overview ¶
Package logger logs one line per request.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(configs ...Config) zinc.Middleware
New logs each request after the rest of the chain has run. A returned error is sent through the application's error handler first, so the logged status is the one the client received.
Types ¶
type Config ¶
type Config struct {
// Logger receives the default log line. If nil, slog.Default() is used.
Logger *slog.Logger
// Log replaces the default log line. It receives every request's values.
Log func(*zinc.Context, Values) error
// Headers lists request headers to copy into Values.Headers.
Headers []string
// QueryParams lists query parameters to copy into Values.QueryParams.
QueryParams []string
// contains filtered or unexported fields
}
Config controls request logging. The zero value logs every request to slog.Default().
type Values ¶
type Values struct {
StartTime time.Time
Latency time.Duration
Method string
URI string
RoutePath string
Status int
Error error
RemoteIP string
Host string
UserAgent string
RequestID string
ContentLength string
ResponseSize int64
Headers map[string][]string
QueryParams map[string][]string
}
Values contains extracted request/response values.
Click to show internal directories.
Click to hide internal directories.