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