slogutil

package
v1.10.26 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TraceIDKey contextKey = "ns_trace_id"
	UserIDKey  contextKey = "ns_user_id"
)

Variables

This section is empty.

Functions

func InitLogger

func InitLogger(service, version, revision string)

InitLogger initializes the global slog logger with CustomHandler

func SetLogLevel added in v1.10.14

func SetLogLevel(level slog.Level)

Types

type CustomHandler

type CustomHandler struct {
	// contains filtered or unexported fields
}

CustomHandler adds trace_id and user_id from the context to every record.

Rendering errors is deliberately not its job. Errors created with github.com/samber/oops implement slog.LogValuer, so the base handler expands their wrap chain, code, attached attributes and stack trace by itself — for any output format.

func NewCustomHandler

func NewCustomHandler(w io.Writer, opts *slog.HandlerOptions) *CustomHandler

NewCustomHandler creates a new CustomHandler

func (*CustomHandler) Enabled

func (h *CustomHandler) Enabled(ctx context.Context, level slog.Level) bool

func (*CustomHandler) Handle

func (h *CustomHandler) Handle(ctx context.Context, record slog.Record) error

func (*CustomHandler) WithAttrs

func (h *CustomHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*CustomHandler) WithGroup

func (h *CustomHandler) WithGroup(name string) slog.Handler

Jump to

Keyboard shortcuts

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