Standard library / log/slog
slog.Record.Clone()
Copy a record so subsequent Add operations do not share mutable attribute state. Expected stdout: '1 2\n'.
Formal Syntax & Structure
go syntaxgo
func (r Record) Clone() RecordReturn Value
Record
Copy a record so subsequent Add operations do not share mutable attribute state.
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) c := r.Clone() c.Add("m", 3) fmt.Println(r.NumAttrs(), c.NumAttrs())}