github.com/AndrienkoAleksandr/go@v0.0.19/src/log/slog/example_test.go (about) 1 // Copyright 2022 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package slog_test 6 7 import ( 8 "log/slog" 9 "log/slog/internal/slogtest" 10 "net/http" 11 "os" 12 "time" 13 ) 14 15 func ExampleGroup() { 16 r, _ := http.NewRequest("GET", "localhost", nil) 17 // ... 18 19 logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{ReplaceAttr: slogtest.RemoveTime})) 20 logger.Info("finished", 21 slog.Group("req", 22 slog.String("method", r.Method), 23 slog.String("url", r.URL.String())), 24 slog.Int("status", http.StatusOK), 25 slog.Duration("duration", time.Second)) 26 27 // Output: 28 // level=INFO msg=finished req.method=GET req.url=localhost status=200 duration=1s 29 }