mirror of https://github.com/golang/go.git
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 #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>
This commit is contained in:
parent
171850f169
commit
9368210508
|
|
@ -414,8 +414,10 @@ func (v Value) append(dst []byte) []byte {
|
||||||
return append(dst, v.duration().String()...)
|
return append(dst, v.duration().String()...)
|
||||||
case KindTime:
|
case KindTime:
|
||||||
return append(dst, v.time().String()...)
|
return append(dst, v.time().String()...)
|
||||||
case KindAny, KindGroup, KindLogValuer:
|
case KindGroup:
|
||||||
return append(dst, fmt.Sprint(v.any)...)
|
return fmt.Append(dst, v.group())
|
||||||
|
case KindAny, KindLogValuer:
|
||||||
|
return fmt.Append(dst, v.any)
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("bad kind: %s", v.Kind()))
|
panic(fmt.Sprintf("bad kind: %s", v.Kind()))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,7 @@ func TestValueString(t *testing.T) {
|
||||||
{StringValue("foo"), "foo"},
|
{StringValue("foo"), "foo"},
|
||||||
{TimeValue(testTime), "2000-01-02 03:04:05 +0000 UTC"},
|
{TimeValue(testTime), "2000-01-02 03:04:05 +0000 UTC"},
|
||||||
{AnyValue(time.Duration(3 * time.Second)), "3s"},
|
{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 {
|
if got := test.v.String(); got != test.want {
|
||||||
t.Errorf("%#v:\ngot %q\nwant %q", test.v, got, test.want)
|
t.Errorf("%#v:\ngot %q\nwant %q", test.v, got, test.want)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue