Documentation ¶
Overview ¶
contextslogger is a package that provides a context key for a logger.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromContext ¶
FromContext returns the Logger stored in ctx by NewContext, or the default Logger if there is none.
Example ¶
package main import ( "context" "io" "log/slog" "github.com/induzo/gocom/contextslogger" ) func main() { textHandler := slog.NewTextHandler(io.Discard, nil) logger := slog.New(textHandler) ctxWithLogger := contextslogger.NewContext(context.Background(), logger) retrievedLogger := contextslogger.FromContext(ctxWithLogger) _ = retrievedLogger }
Output:
func NewContext ¶
NewContext returns a context that contains the given Logger. Use FromContext to retrieve the Logger.
Example ¶
package main import ( "context" "io" "log/slog" "github.com/induzo/gocom/contextslogger" ) func main() { textHandler := slog.NewTextHandler(io.Discard, nil) logger := slog.New(textHandler) _ = contextslogger.NewContext(context.Background(), logger) }
Output:
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.