Standard library / log/slog

slog.Group()

Construct a keyed Group attribute for structured logging. Expected stdout: 'key\n[n=2]\n'.

Formal Syntax & Structure

go syntaxgo
func Group(key string, args ...any) Attr

Parameters & Attributes

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

Return Value

Attr

Construct a keyed Group attribute for structured logging.

Working Example

Example Snippetgo
package main
import (  "fmt"  "log/slog")
func main() { a := slog.Group("key", slog.Int("n", 2)); fmt.Println(a.Key); fmt.Println(a.Value) }
Go Reference