Skip to content

Commit 0eb9e23

Browse files
jbaeric
authored andcommitted
log/slog: fix string representation of Group values
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 <[email protected]> Reviewed-by: Alan Donovan <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 2673c61 commit 0eb9e23

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

Diff for: src/log/slog/value.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,10 @@ func (v Value) append(dst []byte) []byte {
414414
return append(dst, v.duration().String()...)
415415
case KindTime:
416416
return append(dst, v.time().String()...)
417-
case KindAny, KindGroup, KindLogValuer:
418-
return append(dst, fmt.Sprint(v.any)...)
417+
case KindGroup:
418+
return fmt.Append(dst, v.group())
419+
case KindAny, KindLogValuer:
420+
return fmt.Append(dst, v.any)
419421
default:
420422
panic(fmt.Sprintf("bad kind: %s", v.Kind()))
421423
}

Diff for: src/log/slog/value_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func TestValueString(t *testing.T) {
5959
{StringValue("foo"), "foo"},
6060
{TimeValue(testTime), "2000-01-02 03:04:05 +0000 UTC"},
6161
{AnyValue(time.Duration(3 * time.Second)), "3s"},
62+
{GroupValue(Int("a", 1), Bool("b", true)), "[a=1 b=true]"},
6263
} {
6364
if got := test.v.String(); got != test.want {
6465
t.Errorf("%#v:\ngot %q\nwant %q", test.v, got, test.want)

0 commit comments

Comments
 (0)