From c9911b9a842f4399f59957da5622bc535dc2c688 Mon Sep 17 00:00:00 2001 From: Sean Liao Date: Sat, 26 Aug 2023 13:48:38 +0100 Subject: [PATCH] log/slog: package doc fixes Fixes #62286 Change-Id: If463436e3b5ba6e4eb850097395e00482d0dc671 Reviewed-on: https://go-review.googlesource.com/c/go/+/523196 Reviewed-by: Jonathan Amsterdam Reviewed-by: Dmitri Shuralyov Run-TryBot: Sean Liao TryBot-Result: Gopher Robot Auto-Submit: Dmitri Shuralyov --- src/log/slog/doc.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/log/slog/doc.go b/src/log/slog/doc.go index 088df61c6d..c3f90cbbac 100644 --- a/src/log/slog/doc.go +++ b/src/log/slog/doc.go @@ -41,7 +41,7 @@ as a string and passes it to the [log] package. 2022/11/08 15:28:26 INFO hello count=3 For more control over the output format, create a logger with a different handler. -This statement uses [New] to create a new logger with a TextHandler +This statement uses [New] to create a new logger with a [TextHandler] that writes structured records in text form to standard error: logger := slog.New(slog.NewTextHandler(os.Stderr, nil)) @@ -210,7 +210,7 @@ The call is the most efficient way to achieve the same output as - slog.Info("hello", "count", 3) + slog.InfoContext(ctx, "hello", "count", 3) # Customizing a type's logging behavior @@ -231,8 +231,8 @@ and line number of the logging call within the application. This can produce incorrect source information for functions that wrap slog. For instance, if you define this function in file mylog.go: - func Infof(format string, args ...any) { - slog.Default().Info(fmt.Sprintf(format, args...)) + func Infof(logger *slog.Logger, format string, args ...any) { + logger.Info(fmt.Sprintf(format, args...)) } and you call it like this in main.go: -- 2.50.0