Skip to content

Commit

Permalink
structured-logging: enable KobjSlice usage and warn Kobjs usage
Browse files Browse the repository at this point in the history
  • Loading branch information
harshanarayana committed Aug 31, 2022
1 parent ae4889c commit 95c3097
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion logcheck/pkg/logcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func isContextualCall(fName string) bool {
"FlushLogger",
"FromContext",
"KObj",
"KObjs",
"KObjSlice",
"KRef",
"LoggerWithName",
"LoggerWithValues",
Expand Down
5 changes: 5 additions & 0 deletions logcheck/testdata/src/k8s.io/klog/v2/klog.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ func KObjs(obj interface{}) interface{} {
return nil
}

// KObjSlice emulatess klog.KObjSlice
func KObjSlice(obj interface{}) interface{} {
return nil
}

func KRef(namespace, name string) interface{} {
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ func doNotAlllowKlog() {
klog.InfoS("test log") // want `function "InfoS" should not be used, convert to contextual logging`
klog.ErrorS(nil, "test log") // want `function "ErrorS" should not be used, convert to contextual logging`
klog.V(1).Infof("test log") // want `function "V" should not be used, convert to contextual logging` `function "Infof" should not be used, convert to contextual logging`
klog.KObjs(nil) // want `function "KObjs" should not be used, convert to contextual logging`
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

func allowKlog() {
klog.KObj(nil)
klog.KObjs(nil)
klog.KObjSlice(nil)
klog.KRef("", "")
klog.FromContext(nil)
klog.TODO()
Expand Down

0 comments on commit 95c3097

Please sign in to comment.