1
0
mirror of https://github.com/golang/go synced 2024-09-28 18:14:29 -06:00

slog: factoring out code to make the examples playable

For #61885

Change-Id: I5a0006fec2899dcbc989207174f438ecbfcc63ff
Reviewed-on: https://go-review.googlesource.com/c/go/+/536215
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
lotusirous 2023-10-18 22:13:40 +07:00 committed by Jonathan Amsterdam
parent 5b6d3dea87
commit e41fb0fd1a

View File

@ -6,7 +6,6 @@ package slog_test
import (
"log/slog"
"log/slog/internal/slogtest"
"net/http"
"os"
"time"
@ -16,7 +15,16 @@ func ExampleGroup() {
r, _ := http.NewRequest("GET", "localhost", nil)
// ...
logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{ReplaceAttr: slogtest.RemoveTime}))
logger := slog.New(
slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr {
if a.Key == slog.TimeKey && len(groups) == 0 {
return slog.Attr{}
}
return a
},
}),
)
logger.Info("finished",
slog.Group("req",
slog.String("method", r.Method),