mirror of
https://github.com/golang/go.git
synced 2025-05-29 11:25:43 +00: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:
parent
5b6d3dea87
commit
e41fb0fd1a
@ -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),
|
||||
|
Loading…
x
Reference in New Issue
Block a user