You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Existing code generally appears to use one of the 3 options from below,
in ascending order of popularity.
// Option 1: Unintuitive group constructiong:=slog.Any("key", slog.GroupValue(attrs...))
// Option 2: convert to []any with a helper funcg:=slog.Group("key", attr2any(attrs)...)
// Option 3: just use []anyvarattrs []any...g:=slog.Group("key", attrs...)
This appears to be the only gap in slog's exposed api where any is unavoidable,
and can't be escaped by using an alternate frontend (replace slog.Logger with something else while keeping slog.Handler) because Attrs are how key-value pairs are communicated to handlers.
Proposal Details
I propose the addition of the above function to allow for the type safe construction of Group attributes.
The existing signature works if you know the list of attributes to use upfront:
but less well if you need to construct the group members beforehand.
Existing code generally appears to use one of the 3 options from below,
in ascending order of popularity.
This appears to be the only gap in slog's exposed api where
any
is unavoidable,and can't be escaped by using an alternate frontend (replace
slog.Logger
with something else while keepingslog.Handler
) because Attrs are how key-value pairs are communicated to handlers.cc @jba
The text was updated successfully, but these errors were encountered: