Documentation
¶
Overview ¶
Package logging provides helper functions to use a structured logger.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewJsonLogger ¶
NewJsonLogger creates a new structured logger in JSON format.
func WithLogging ¶ added in v0.1.93
func WithLogging(logger *slog.Logger, next http.HandlerFunc) http.HandlerFunc
WithLogging logs the request with method, path and duration without path masking. To mask sensitive path segments, use WithLoggingCustom with a configured PathSanitizer.
func WithLoggingCustom ¶ added in v0.4.9
func WithLoggingCustom(logger *slog.Logger, sanitizer *PathSanitizer, next http.HandlerFunc) http.HandlerFunc
WithLoggingCustom logs the request with method, path and duration using a custom path sanitizer.
Types ¶
type PathSanitizer ¶ added in v0.4.9
type PathSanitizer struct {
// PathValues maps path parameter names to their placeholder representations.
PathValues map[string]string
}
PathSanitizer configures which path segments should be masked during logging. Example usage:
sanitizer := logging.NewPathSanitizer(map[string]string{
"session_id": "{session_id}",
"user_id": "{user_id}",
"order_id": "{order_id}",
})
handler := logging.WithLoggingCustom(logger, sanitizer, nextHandler)
func NewPathSanitizer ¶ added in v0.4.9
func NewPathSanitizer(pathValues map[string]string) *PathSanitizer
NewPathSanitizer creates a custom path sanitizer with specified path values.
Click to show internal directories.
Click to hide internal directories.