1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2026-06-03 18:35:08 +02:00

log: Add String method to Value and KeyValue (#5117)

This commit is contained in:
Robert Pająk
2024-04-02 10:50:07 +02:00
committed by GitHub
parent b7fdeb9f3a
commit e6e44dee90
3 changed files with 63 additions and 0 deletions
+19
View File
@@ -264,6 +264,25 @@ func TestEmpty(t *testing.T) {
t.Run("AsMap", testErrKind(v.AsMap, "AsMap", k))
}
func TestValueString(t *testing.T) {
for _, test := range []struct {
v log.Value
want string
}{
{log.Int64Value(-3), "-3"},
{log.Float64Value(.15), "0.15"},
{log.BoolValue(true), "true"},
{log.StringValue("foo"), "foo"},
{log.BytesValue([]byte{2, 4, 6}), "[2 4 6]"},
{log.SliceValue(log.IntValue(3), log.StringValue("foo")), "[3 foo]"},
{log.MapValue(log.Int("a", 1), log.Bool("b", true)), "[a:1 b:true]"},
{log.Value{}, "<nil>"},
} {
got := test.v.String()
assert.Equal(t, test.want, got)
}
}
type logSink struct {
logr.LogSink