]> Cypherpunks.ru repositories - gostls13.git/commit
log/slog: JSONHandler elides empty groups even with replacement
authorJonathan Amsterdam <jba@google.com>
Wed, 20 Sep 2023 19:45:08 +0000 (15:45 -0400)
committerJonathan Amsterdam <jba@google.com>
Mon, 2 Oct 2023 13:57:53 +0000 (13:57 +0000)
commitdeb8e29000ebecbd788e0e86e239d52c26707457
treefee0ba49432c559c76ebbedaaf506b375916e241
parent3fb1d95149fa280343581a48547c3c3f70dac5fb
log/slog: JSONHandler elides empty groups even with replacement

Previously, the built-in handlers assumed a group was empty if and
only if it had no attributes. But a ReplaceAttr function that
returned an empty Attr could produce an empty group even if the group
had attrs prior to replacement.

The obvious solution, doing the replacement first and then checking,
would require allocating storage to hold the replaced Attrs.  Instead,
we write to the buffer, and if no attributes were written, we back up
to before the group name.

Fixes #62512.

Change-Id: I140e0901f4b157e36594d8d476f1ab326f8f2c2a
Reviewed-on: https://go-review.googlesource.com/c/go/+/529855
Run-TryBot: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
src/log/slog/handler.go
src/log/slog/handler_test.go
src/log/slog/internal/buffer/buffer.go