Documentation ¶
Overview ¶
package slogx provides various helpers to wrok with the stdlib's "log/slog" package see https://pkg.go.dev/log/slog https://gist.github.com/wijayaerick/de3de10c47a79d5310968ba5ff101a19 https://github.com/golang/go/issues/56345 https://go.googlesource.com/proposal/+/master/design/56345-structured-logging.md https://github.com/golang/go/wiki/Resources-for-slog
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Fatal ¶
TODO: use actual fatal level https://opentelemetry.io/docs/reference/specification/logs/data-model/#example-mappings
func FromCtx ¶
FromCtx returns the Logger associated with the ctx. If no logger is associated, a New() logger is returned with a addedfield "slogx.FromCtx": "error".
For example, to add a field to an existing logger in the context, use this notation:
ctx := r.Context() logger := slogx.FromCtx(ctx) logger = logger.With(...)
Types ¶
type DiscardHandler ¶
type DiscardHandler struct { }
func NewDiscardHandler ¶
func NewDiscardHandler() *DiscardHandler
NewDiscardHandler returns a new DiscardHandler that do nothing and discards logs
type MultiHandler ¶
type MultiHandler struct {
// contains filtered or unexported fields
}
func NewMultiHandler ¶
func NewMultiHandler(handlers ...slog.Handler) *MultiHandler