Standard library / log/slog

slog.Record.Add()

Append attributes supplied as key/value pairs or Attr values. Expected stdout: '1\n'.

Formal Syntax & Structure

go syntaxgo
func (r *Record) Add(args ...any)

Parameters & Attributes

NameTypeDescription
args...anyAlternating key/value pairs or Attr values.

Working Example

Example Snippetgo
package main
import (  "fmt"  "log/slog"  "time")
func main() {  r := slog.NewRecord(time.Time{}, slog.LevelInfo, "ready", 0)  r.Add("n", 2)  fmt.Println(r.NumAttrs())}
Go Reference