]> Cypherpunks repositories - gostls13.git/commitdiff
log/slog: package doc fixes
authorSean Liao <sean@liao.dev>
Sat, 26 Aug 2023 12:48:38 +0000 (13:48 +0100)
committerGopher Robot <gobot@golang.org>
Wed, 30 Aug 2023 19:31:37 +0000 (19:31 +0000)
Fixes #62286

Change-Id: If463436e3b5ba6e4eb850097395e00482d0dc671
Reviewed-on: https://go-review.googlesource.com/c/go/+/523196
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Sean Liao <sean@liao.dev>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>

src/log/slog/doc.go

index 088df61c6de7896fe3ec4845da2b075ffc0e5d66..c3f90cbbacefbf07335d1bb829e909e984e42a37 100644 (file)
@@ -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: