Source file
src/log/slog/example_logvaluer_secret_test.go
1
2
3
4
5 package slog_test
6
7 import (
8 "log/slog"
9 "log/slog/internal/slogtest"
10 "os"
11 )
12
13
14 type Token string
15
16
17
18 func (Token) LogValue() slog.Value {
19 return slog.StringValue("REDACTED_TOKEN")
20 }
21
22
23
24 func ExampleLogValuer_secret() {
25 t := Token("shhhh!")
26 logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{ReplaceAttr: slogtest.RemoveTime}))
27 logger.Info("permission granted", "user", "Perry", "token", t)
28
29
30
31 }
32
View as plain text