logging

package
v0.5.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 18, 2026 License: MIT Imports: 5 Imported by: 0

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

func NewJsonLogger() *slog.Logger

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.

func (*PathSanitizer) Sanitize added in v0.4.9

func (ps *PathSanitizer) Sanitize(r *http.Request) string

Sanitize applies masking rules to the HTTP request path.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL