Skip to content

Commit c9911b9

Browse files
seankhliaogopherbot
authored andcommitted
log/slog: package doc fixes
Fixes #62286 Change-Id: If463436e3b5ba6e4eb850097395e00482d0dc671 Reviewed-on: https://go-review.googlesource.com/c/go/+/523196 Reviewed-by: Jonathan Amsterdam <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Run-TryBot: Sean Liao <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Dmitri Shuralyov <[email protected]>
1 parent fc486e4 commit c9911b9

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/log/slog/doc.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ as a string and passes it to the [log] package.
4141
2022/11/08 15:28:26 INFO hello count=3
4242
4343
For more control over the output format, create a logger with a different handler.
44-
This statement uses [New] to create a new logger with a TextHandler
44+
This statement uses [New] to create a new logger with a [TextHandler]
4545
that writes structured records in text form to standard error:
4646
4747
logger := slog.New(slog.NewTextHandler(os.Stderr, nil))
@@ -210,7 +210,7 @@ The call
210210
211211
is the most efficient way to achieve the same output as
212212
213-
slog.Info("hello", "count", 3)
213+
slog.InfoContext(ctx, "hello", "count", 3)
214214
215215
# Customizing a type's logging behavior
216216
@@ -231,8 +231,8 @@ and line number of the logging call within the application. This can produce
231231
incorrect source information for functions that wrap slog. For instance, if you
232232
define this function in file mylog.go:
233233
234-
func Infof(format string, args ...any) {
235-
slog.Default().Info(fmt.Sprintf(format, args...))
234+
func Infof(logger *slog.Logger, format string, args ...any) {
235+
logger.Info(fmt.Sprintf(format, args...))
236236
}
237237
238238
and you call it like this in main.go:

0 commit comments

Comments
 (0)