The one Attr constructor not yet covered:
func Group
func Group(key string, args ...any) AttrGroup returns an Attr for a Group Value. The first argument is the key; the remaining arguments are converted to Attrs as in Logger.Log.
Use Group to collect several key-value pairs under a single key on a log line, or as the result of LogValue in order to log a single value as multiple Attrs.
Groups are conceptually simple. They’re how we nest log attributes under a common key, as we can see in the inline example:
logger.Info("finished", slog.Group("req", slog.String("method", r.Method), slog.String("url", r.URL.String())), slog.Int("status", http.StatusOK), slog.Duration("duration", time.Second))
For the default TextHandler, groups are logged with the full key path in dot-separated notation:
level=INFO msg=finished req.method=GET req.url=localhost status=200 duration=1s
For the JSONHandler, they’re logged as inline JSON objects:
{"level":"INFO","msg":"finished","req":{"method":"GET","url":"localhost"},"status":200,"duration":1000000000}