github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/log/slog/example_logvaluer_secret_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  	"github.com/shogo82148/std/log/slog"
     9  	"github.com/shogo82148/std/log/slog/internal/slogtest"
    10  	"github.com/shogo82148/std/os"
    11  )
    12  
    13  // A token is a secret value that grants permissions.
    14  type Token string
    15  
    16  // この例では、自身を置き換えるValueを使用して、秘密を明らかにしないようにする方法を示します。
    17  func ExampleLogValuer_secret() {
    18  	t := Token("shhhh!")
    19  	logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{ReplaceAttr: slogtest.RemoveTime}))
    20  	logger.Info("permission granted", "user", "Perry", "token", t)
    21  
    22  	// Output:
    23  	// level=INFO msg="permission granted" user=Perry token=REDACTED_TOKEN
    24  }