Standard library / log/slog

slog.Record.Attrs()

Visit each attribute until the callback returns false. Expected stdout: 'n=2\n'.

Formal Syntax & Structure

go syntaxgo
func (r Record) Attrs(f func(Attr) bool)

Parameters & Attributes

NameTypeDescription
ffunc(Attr) boolInput to the operation as described above.

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, "m", 3)  r.Attrs(func(a slog.Attr) bool { fmt.Println(a); return false })}
Go Reference