slogutil

package
v1.10.41 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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