Documentation ¶
Overview ¶
Package lg contains utility functions for working with slog. It implements the slog.NewContext and slog.FromContext funcs that have recently been zapped from the slog proposal. I think you had it right the first time, Go team. Hopefully this package is short-lived and those funcs are put back.
Index ¶
- func Discard() *slog.Logger
- func Error(log *slog.Logger, msg string, err error, args ...any)
- func FromContext(ctx context.Context) *slog.Logger
- func NewContext(ctx context.Context, l *slog.Logger) context.Context
- func Unexpected(log *slog.Logger, err error)
- func WarnIfCloseError(log *slog.Logger, msg string, c io.Closer)
- func WarnIfError(log *slog.Logger, msg string, err error)
- func WarnIfFuncError(log *slog.Logger, msg string, fn func() error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromContext ¶
FromContext returns the Logger stored in ctx by NewContext, or the Discard logger if there is none.
func NewContext ¶
NewContext returns a context that contains the given Logger. Use FromContext to retrieve the Logger.
func Unexpected ¶
Unexpected is a convenience function for logging unexpected errors for which there may not be any useful context message.
func WarnIfCloseError ¶
WarnIfCloseError executes c.Close if is non-nil, and logs a warning if c.Close returns an error.
func WarnIfError ¶
WarnIfError logs a warning if err is non-nil.
Types ¶
This section is empty.
Directories ¶
Path | Synopsis |
---|---|
Package lga ("log attribute") holds constants for log attribute names.
|
Package lga ("log attribute") holds constants for log attribute names. |
Package lgm ("log message") contains constants for log messages.
|
Package lgm ("log message") contains constants for log messages. |
Package slogbuf implements a Buffer that stores log records that can later be replayed on a slog.Handler.
|
Package slogbuf implements a Buffer that stores log records that can later be replayed on a slog.Handler. |
Package userlogdir has a single function, UserLogDir, that returns an OS-specific path for storing user logs.
|
Package userlogdir has a single function, UserLogDir, that returns an OS-specific path for storing user logs. |