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) AttrParameters & Attributes
| Name | Type | Description |
|---|---|---|
| key | string | Attribute key. |
| args | ...any | Alternating 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) }