log

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LevelDebug = slog.LevelDebug
	LevelInfo  = slog.LevelInfo
	LevelWarn  = slog.LevelWarn
	LevelError = slog.LevelError
)

Alias slog levels for convenience.

View Source
const (
	// CorrelationIDHeader is the HTTP header name for correlation IDs.
	CorrelationIDHeader = "X-Correlation-ID"
)

Variables

This section is empty.

Functions

func CorrelationIDMiddleware

func CorrelationIDMiddleware(next http.Handler) http.Handler

CorrelationIDMiddleware adds correlation IDs to requests for tracing.

func Debug

func Debug(ctx context.Context, msg string, keysAndValues ...any)

Debug logs a debug message with key-value pairs.

func Error

func Error(ctx context.Context, err error, msg string, keysAndValues ...any)

Error logs an error message with key-value pairs.

func Info

func Info(ctx context.Context, msg string, keysAndValues ...any)

Info logs an info message with key-value pairs.

func InitializeLogger

func InitializeLogger(debugLogging bool)

InitializeLogger sets up the global default logger.

func IsSensitiveKey

func IsSensitiveKey(key string) bool

IsSensitiveKey checks if a log key contains sensitive information.

func Log added in v0.1.2

func Log(ctx context.Context, level slog.Level, msg string, keysAndValues ...any)

Log logs a message at the specified level with key-value pairs.

func LoggingMiddleware

func LoggingMiddleware(next http.Handler, opts ...func(*LoggingOptions)) http.Handler

LoggingMiddleware logs HTTP requests with structured logging.

func Warn

func Warn(ctx context.Context, msg string, keysAndValues ...any)

Warn logs a warning message with key-value pairs.

func WithCorrelationID

func WithCorrelationID(ctx context.Context, correlationID string) context.Context

WithCorrelationID adds a correlation ID to the logging context.

func WithDebugHealthChecks added in v0.2.0

func WithDebugHealthChecks(enabled bool) func(*LoggingOptions)

WithDebugHealthChecks enables or disables debug logging for health check endpoints.

func WithLogger

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

WithLogger adds a logger to the context.

func WithName

func WithName(ctx context.Context, name string) context.Context

WithName returns a context with a logger that includes an additional name component.

func WithValues

func WithValues(ctx context.Context, keysAndValues ...any) context.Context

WithValues returns a context with a logger that includes additional key-value pairs.

Types

type LoggingOptions added in v0.2.0

type LoggingOptions struct {
	DebugHealthChecks bool
}

LoggingOptions holds configuration for the logging middleware.

Jump to

Keyboard shortcuts

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