Skip to content

Commit

Permalink
log/slog: fix string representation of Group values
Browse files Browse the repository at this point in the history
Format Group values like a []Attr, rather than a *Attr.

Also, use fmt.Append in Value.append.

Updates golang#56345.

Change-Id: I9db1a8ec47f8e99c1ac3225d78e152013116bff3
Reviewed-on: https://go-review.googlesource.com/c/go/+/479515
Run-TryBot: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
  • Loading branch information
jba authored and eric committed Sep 7, 2023
1 parent 2673c61 commit 0eb9e23
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/log/slog/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,10 @@ func (v Value) append(dst []byte) []byte {
return append(dst, v.duration().String()...)
case KindTime:
return append(dst, v.time().String()...)
case KindAny, KindGroup, KindLogValuer:
return append(dst, fmt.Sprint(v.any)...)
case KindGroup:
return fmt.Append(dst, v.group())
case KindAny, KindLogValuer:
return fmt.Append(dst, v.any)
default:
panic(fmt.Sprintf("bad kind: %s", v.Kind()))
}
Expand Down
1 change: 1 addition & 0 deletions src/log/slog/value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func TestValueString(t *testing.T) {
{StringValue("foo"), "foo"},
{TimeValue(testTime), "2000-01-02 03:04:05 +0000 UTC"},
{AnyValue(time.Duration(3 * time.Second)), "3s"},
{GroupValue(Int("a", 1), Bool("b", true)), "[a=1 b=true]"},
} {
if got := test.v.String(); got != test.want {
t.Errorf("%#v:\ngot %q\nwant %q", test.v, got, test.want)
Expand Down

0 comments on commit 0eb9e23

Please sign in to comment.