From 59f7cb505f581aa4df72c5d4a1a563a1bf461224 Mon Sep 17 00:00:00 2001 From: yuzhiquan Date: Mon, 10 May 2021 10:43:34 +0800 Subject: [PATCH] fix byte array display in InfoS and ErrorS --- klog.go | 2 ++ klog_test.go | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/klog.go b/klog.go index f04b85d4..c0080c0b 100644 --- a/klog.go +++ b/klog.go @@ -825,6 +825,8 @@ func kvListFormat(b *bytes.Buffer, keysAndValues ...interface{}) { switch v.(type) { case string, error: b.WriteString(fmt.Sprintf("%s=%q", k, v)) + case []byte: + b.WriteString(fmt.Sprintf("%s=%+q", k, v)) default: if _, ok := v.(fmt.Stringer); ok { b.WriteString(fmt.Sprintf("%s=%q", k, v)) diff --git a/klog_test.go b/klog_test.go index b7f01238..c0370c78 100644 --- a/klog_test.go +++ b/klog_test.go @@ -1067,6 +1067,14 @@ func TestKvListFormat(t *testing.T) { keysValues: []interface{}{"pod", "kubedns", "values", []string{"deployment", "svc", "configmap"}}, want: " pod=\"kubedns\" values=[deployment svc configmap]", }, + { + keysValues: []interface{}{"pod", "kubedns", "bytes", []byte("test case for byte array")}, + want: " pod=\"kubedns\" bytes=\"test case for byte array\"", + }, + { + keysValues: []interface{}{"pod", "kubedns", "bytes", []byte("��=� ⌘")}, + want: " pod=\"kubedns\" bytes=\"\\ufffd\\ufffd=\\ufffd \\u2318\"", + }, { keysValues: []interface{}{"pod", "kubedns", "maps", map[string]int{"three": 4}}, want: " pod=\"kubedns\" maps=map[three:4]",