Help us shape the future of Go! Take the 2026 Go Developer Survey

contextlogger

package
v0.0.41 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildAttributes

func BuildAttributes(ctx context.Context, r *http.Request, extractFunc func(ctx context.Context, r *http.Request) map[string]interface{}) []interface{}

Headers and extra attributes are json.Marshaled, but if that fails, the headers are sent to kusto as the original map[string]string The function logs to CtxLog to notify users of the error if they wish to fix it

func DefaultExtractor

func DefaultExtractor(ctx context.Context, r *http.Request) map[string]interface{}

DefaultExtractor extracts operation request fields from the context. It returns the filtered map containing only the specified keys.

func GetLogger

func GetLogger(ctx context.Context) *log.Logger

func New

func New(logger log.Logger, extractFunction ExtractFunction) mux.MiddlewareFunc

New creates a context logging middleware. Parameters

logger:                  A slog.Logger instance used for logging. Any static attributes added to this logger before passing it in will be preserved
extractFunction:         ExtractFunction extracts information from the ctx and/or the request and put it in the logger

func WithLogger added in v0.0.37

func WithLogger(ctx context.Context, logger *log.Logger) context.Context

Types

type ExtractFunction

type ExtractFunction func(ctx context.Context, r *http.Request) map[string]interface{}

Jump to

Keyboard shortcuts

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