diff --git a/internal/serialize/keyvalues.go b/internal/serialize/keyvalues.go index cb97576b..f85d7ccf 100644 --- a/internal/serialize/keyvalues.go +++ b/internal/serialize/keyvalues.go @@ -109,10 +109,10 @@ func KVListFormat(b *bytes.Buffer, keysAndValues ...interface{}) { // https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/migration-to-structured-logging.md#name-arguments // for the sake of performance. Keys with spaces, // special characters, etc. will break parsing. - if k, ok := k.(string); ok { + if sK, ok := k.(string); ok { // Avoid one allocation when the key is a string, which // normally it should be. - b.WriteString(k) + b.WriteString(sK) } else { b.WriteString(fmt.Sprintf("%s", k)) } diff --git a/internal/serialize/keyvalues_test.go b/internal/serialize/keyvalues_test.go index 79260092..d4b33851 100644 --- a/internal/serialize/keyvalues_test.go +++ b/internal/serialize/keyvalues_test.go @@ -140,6 +140,18 @@ No whitespace.`, keysValues: []interface{}{"point-1", point{100, 200}, "point-2", emptyPoint}, want: " point-1=\"x=100, y=200\" point-2=\"\"", }, + { + keysValues: []interface{}{struct{ key string }{key: "k1"}, "value"}, + want: " {k1}=\"value\"", + }, + { + keysValues: []interface{}{1, "test"}, + want: " %!s(int=1)=\"test\"", + }, + { + keysValues: []interface{}{map[string]string{"k": "key"}, "value"}, + want: " map[k:key]=\"value\"", + }, } for _, d := range testKVList {