diff --git a/klog.go b/klog.go index de49e85e..ac3fbb0f 100644 --- a/klog.go +++ b/klog.go @@ -800,10 +800,16 @@ func kvListFormat(b *bytes.Buffer, keysAndValues ...interface{}) { v = missingValue } b.WriteByte(' ') - if _, ok := v.(fmt.Stringer); ok { + + switch v.(type) { + case string: b.WriteString(fmt.Sprintf("%s=%q", k, v)) - } else { - b.WriteString(fmt.Sprintf("%s=%#v", k, v)) + default: + if _, ok := v.(fmt.Stringer); ok { + b.WriteString(fmt.Sprintf("%s=%q", k, v)) + } else { + b.WriteString(fmt.Sprintf("%s=%+v", k, v)) + } } } } diff --git a/klog_test.go b/klog_test.go index 58b384e4..40a0ca3c 100644 --- a/klog_test.go +++ b/klog_test.go @@ -849,20 +849,21 @@ func TestKvListFormat(t *testing.T) { keysValues: []interface{}{"pod", "kubedns", "spec", struct { X int Y string - }{X: 76, Y: "strval"}}, - want: " pod=\"kubedns\" spec=struct { X int; Y string }{X:76, Y:\"strval\"}", + N time.Time + }{X: 76, Y: "strval", N: time.Date(2006, 1, 2, 15, 4, 5, .067890e9, time.UTC)}}, + want: " pod=\"kubedns\" spec={X:76 Y:strval N:2006-01-02 15:04:05.06789 +0000 UTC}", }, { keysValues: []interface{}{"pod", "kubedns", "values", []int{8, 6, 7, 5, 3, 0, 9}}, - want: " pod=\"kubedns\" values=[]int{8, 6, 7, 5, 3, 0, 9}", + want: " pod=\"kubedns\" values=[8 6 7 5 3 0 9]", }, { keysValues: []interface{}{"pod", "kubedns", "values", []string{"deployment", "svc", "configmap"}}, - want: " pod=\"kubedns\" values=[]string{\"deployment\", \"svc\", \"configmap\"}", + want: " pod=\"kubedns\" values=[deployment svc configmap]", }, { keysValues: []interface{}{"pod", "kubedns", "maps", map[string]int{"three": 4}}, - want: " pod=\"kubedns\" maps=map[string]int{\"three\":4}", + want: " pod=\"kubedns\" maps=map[three:4]", }, { keysValues: []interface{}{"pod", KRef("kube-system", "kubedns"), "status", "ready"},