Standard library / log/slog

slog.LogValuer

Interface for custom structured value representation; useful for redacting sensitive types. Expected stdout: '[redacted]\n'.

Formal Syntax & Structure

go syntaxgo
type LogValuer interface {  LogValue() Value}

Working Example

Example Snippetgo
package main
import (  "fmt"  "log/slog")
type secret string
func (s secret) LogValue() slog.Value { return slog.StringValue("[redacted]") }
func main() { var s slog.LogValuer = secret("demo"); fmt.Println(s.LogValue()) }
Go Reference