Hi Steve, I'm not sure what the right answer is. Can you file this as a bug on go.dev/issues?
On Thursday, September 7, 2023 at 2:30:09 PM UTC-4 Steven Pelley wrote: > Hi everyone, > > Possibly a bug or potential improvement in slog. > This will sound excessively complicated, which I recognize and have > changed my approach. Regardless, I see an opportunity to improve > surprising behavior. > I'm looking for feedback on whether I missed something in the slog > documentation or if this is a valid bug or improvement, in which case I can > file it. > > slog.Value always json.marshals to an empty document, "{}", which to me > was surprising behavior when using JsonHandler. If a slog.Value is > embedded in a logged non-slog.Value, for example a slice, it will > effectively omit data. On the other hand any tree of Values and Attrs > passed directly to the log functions, without an intervening non-slog.Value > object, marshals and logs properly. I expect a slice, or any other > non-slog.Value type, containing an slog.Value to marshal to json with the > slog.Value's represented value. > > Alternatively, the slog documentation (or specifically JsonHandler) could > state that no non-slog.Value object passed to a log method may contain an > slog.Value, and that LogValuers must maintain this invariant. > > go1.21.0 darwin/arm64 > demonstration <https://goplay.tools/snippet/H26amsQBiYG> > > I discovered this when logging (using JsonHandler) an object containing a > list of objects whose logged data I wanted to redact/reduce. I do this as > a LogValuer whose LogValue function constructs and returns a new > slog.GroupValue with a []slog.Value containing the redacted objects for > logging. Each Value is created by in turn calling > Value.Resolve(Value.anyValue(...)) on the component items. The resulting > log contains a list of empty documents. I think this is a reasonable use > of LogValue, though I recognize that many people will suggest not logging > slices. > > Thanks, > Steve > > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/04a3cff1-557f-4642-a3f3-479266b7a6dbn%40googlegroups.com.