@@ -41,7 +41,7 @@ as a string and passes it to the [log] package.
41
41
2022/11/08 15:28:26 INFO hello count=3
42
42
43
43
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]
45
45
that writes structured records in text form to standard error:
46
46
47
47
logger := slog.New(slog.NewTextHandler(os.Stderr, nil))
@@ -210,7 +210,7 @@ The call
210
210
211
211
is the most efficient way to achieve the same output as
212
212
213
- slog.Info( "hello", "count", 3)
213
+ slog.InfoContext(ctx, "hello", "count", 3)
214
214
215
215
# Customizing a type's logging behavior
216
216
@@ -231,8 +231,8 @@ and line number of the logging call within the application. This can produce
231
231
incorrect source information for functions that wrap slog. For instance, if you
232
232
define this function in file mylog.go:
233
233
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...))
236
236
}
237
237
238
238
and you call it like this in main.go:
0 commit comments