Skip to content

Commit

Permalink
Merge pull request kubernetes#88 from vincepri/remove-klog-info-level
Browse files Browse the repository at this point in the history
Remove "level" from klogr Info
  • Loading branch information
k8s-ci-robot authored Aug 13, 2019
2 parents 3ca30a5 + dab77b7 commit 4527d85
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
3 changes: 1 addition & 2 deletions klogr/klogr.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,11 @@ func pretty(value interface{}) string {

func (l klogger) Info(msg string, kvList ...interface{}) {
if l.Enabled() {
lvlStr := flatten("level", l.level)
msgStr := flatten("msg", msg)
trimmed := trimDuplicates(l.values, kvList)
fixedStr := flatten(trimmed[0]...)
userStr := flatten(trimmed[1]...)
klog.InfoDepth(framesToCaller(), l.prefix, " ", lvlStr, " ", msgStr, " ", fixedStr, " ", userStr)
klog.InfoDepth(framesToCaller(), l.prefix, " ", msgStr, " ", fixedStr, " ", userStr)
}
}

Expand Down
20 changes: 7 additions & 13 deletions klogr/klogr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,54 +28,48 @@ func TestInfo(t *testing.T) {
klogr: New().V(0),
text: "test",
keysAndValues: []interface{}{"akey", "avalue"},
expectedOutput: ` "level"=0 "msg"="test" "akey"="avalue"
expectedOutput: ` "msg"="test" "akey"="avalue"
`,
},
"should not print duplicate keys with the same value": {
klogr: New().V(0),
text: "test",
keysAndValues: []interface{}{"akey", "avalue", "akey", "avalue"},
expectedOutput: ` "level"=0 "msg"="test" "akey"="avalue"
expectedOutput: ` "msg"="test" "akey"="avalue"
`,
},
"should only print the last duplicate key when the values are passed to Info": {
klogr: New().V(0),
text: "test",
keysAndValues: []interface{}{"akey", "avalue", "akey", "avalue2"},
expectedOutput: ` "level"=0 "msg"="test" "akey"="avalue2"
expectedOutput: ` "msg"="test" "akey"="avalue2"
`,
},
"should only print the duplicate key that is passed to Info if one was passed to the logger": {
klogr: New().WithValues("akey", "avalue"),
text: "test",
keysAndValues: []interface{}{"akey", "avalue"},
expectedOutput: ` "level"=0 "msg"="test" "akey"="avalue"
expectedOutput: ` "msg"="test" "akey"="avalue"
`,
},
"should only print the key passed to Info when one is already set on the logger": {
klogr: New().WithValues("akey", "avalue"),
text: "test",
keysAndValues: []interface{}{"akey", "avalue2"},
expectedOutput: ` "level"=0 "msg"="test" "akey"="avalue2"
`,
},
"should print different log level if set": {
klogr: New().V(4),
text: "test",
expectedOutput: ` "level"=4 "msg"="test"
expectedOutput: ` "msg"="test" "akey"="avalue2"
`,
},
"should correctly handle odd-numbers of KVs": {
text: "test",
keysAndValues: []interface{}{"akey", "avalue", "akey2"},
expectedOutput: ` "level"=0 "msg"="test" "akey"="avalue" "akey2"=null
expectedOutput: ` "msg"="test" "akey"="avalue" "akey2"=null
`,
},
"should correctly handle odd-numbers of KVs in both log values and Info args": {
klogr: New().WithValues("basekey1", "basevar1", "basekey2"),
text: "test",
keysAndValues: []interface{}{"akey", "avalue", "akey2"},
expectedOutput: ` "level"=0 "msg"="test" "basekey1"="basevar1" "basekey2"=null "akey"="avalue" "akey2"=null
expectedOutput: ` "msg"="test" "basekey1"="basevar1" "basekey2"=null "akey"="avalue" "akey2"=null
`,
},
}
Expand Down

0 comments on commit 4527d85

Please sign in to comment.