From: Sean Liao Date: Sat, 26 Aug 2023 12:48:38 +0000 (+0100) Subject: log/slog: package doc fixes X-Git-Tag: go1.22rc1~1034 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=c9911b9a842f4399f59957da5622bc535dc2c688;p=gostls13.git 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 --- 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: