Standard library / log/slog
slog.Record.AddAttrs()
Append typed attributes. Expected stdout: '1\n'.
Formal Syntax & Structure
go syntaxgo
func (r *Record) AddAttrs(attrs ...Attr)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| attrs | ...Attr | Structured attributes. |
Working Example
Example Snippetgo
package main
import ( "fmt" "log/slog" "time")
func main() { r := slog.NewRecord(time.Time{}, slog.LevelInfo, "ready", 0) r.AddAttrs(slog.Int("n", 2)) fmt.Println(r.NumAttrs())}