Documentation
¶
Index ¶
- func AddAttributesToLogger(ctx context.Context, args ...any) context.Context
- func GetLogger(ctx context.Context) *slog.Logger
- func SetDefaultLogger(logger *slog.Logger)
- func SetSlogPackageDefault()
- func SetSlogPackageWithOptions(writer io.Writer, opts *slog.HandlerOptions)
- func With(ctx context.Context, args ...any) context.Context
- func WithAttrs(ctx context.Context, attrs ...slog.Attr) context.Context
- type ContextHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddAttributesToLogger ¶ added in v1.0.1
AddAttributesToLogger is now an alias for With
func GetLogger ¶ added in v1.0.1
GetLogger is used to get the context logger It is recommended to use slog context functions instead ex slog.InfoContext(ctx, msg, ...args)
func SetDefaultLogger ¶ added in v1.1.0
SetDefaultLogger sets the default logger for this package (slogctx)
func SetSlogPackageDefault ¶ added in v1.1.0
func SetSlogPackageDefault()
Calls slog.SetDefault with a JSONHandler that logs to Stdout wrapped in a ContextHandler
func SetSlogPackageWithOptions ¶ added in v1.1.0
func SetSlogPackageWithOptions(writer io.Writer, opts *slog.HandlerOptions)
Calls slog.SetDefault with options passed to a JSONHandler that logs to Stdout wrapped in a ContextHandler
func With ¶ added in v1.1.0
With is used to add values to the context for logging purposes these args will appear in logs of any child contexts where slogctx.GetLogger(ctx) is called or any slog context functions for example slog.InfoContext(ctx, msg, ...args)
Types ¶
type ContextHandler ¶ added in v1.1.0
type ContextHandler struct {
// contains filtered or unexported fields
}
ContextHandler enables this package to handle passing values from context to log messages when using the slog context functions ex: slog.InfoContext(ctx, msg, ...args)
func NewContextHandler ¶ added in v1.1.0
func NewContextHandler(handler slog.Handler) *ContextHandler
NewContextHandler creates a new ContextHandler that wraps a slog.Handler passed in
func NewJSONContextHandler ¶ added in v1.1.0
func NewJSONContextHandler(w io.Writer, opts *slog.HandlerOptions) *ContextHandler
NewJSONContextHandler creates a new ContextHandler that wraps a slog.JSONHandler