diff --git a/logcheck/pkg/logcheck.go b/logcheck/pkg/logcheck.go index 2973360..5a05320 100644 --- a/logcheck/pkg/logcheck.go +++ b/logcheck/pkg/logcheck.go @@ -314,7 +314,7 @@ func isContextualCall(fName string) bool { "FlushLogger", "FromContext", "KObj", - "KObjs", + "KObjSlice", "KRef", "LoggerWithName", "LoggerWithValues", diff --git a/logcheck/testdata/src/k8s.io/klog/v2/klog.go b/logcheck/testdata/src/k8s.io/klog/v2/klog.go index d62a5d4..955c8e4 100644 --- a/logcheck/testdata/src/k8s.io/klog/v2/klog.go +++ b/logcheck/testdata/src/k8s.io/klog/v2/klog.go @@ -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 } diff --git a/logcheck/testdata/src/onlyAllowContextual/onlyAllowContextual.go b/logcheck/testdata/src/onlyAllowContextual/onlyAllowContextual.go index 4cc5e12..cd67ca8 100644 --- a/logcheck/testdata/src/onlyAllowContextual/onlyAllowContextual.go +++ b/logcheck/testdata/src/onlyAllowContextual/onlyAllowContextual.go @@ -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` } diff --git a/logcheck/testdata/src/onlyAllowContextual/whitelistedKlog.go b/logcheck/testdata/src/onlyAllowContextual/whitelistedKlog.go index 07bb2a2..6acce7c 100644 --- a/logcheck/testdata/src/onlyAllowContextual/whitelistedKlog.go +++ b/logcheck/testdata/src/onlyAllowContextual/whitelistedKlog.go @@ -27,7 +27,7 @@ import ( func allowKlog() { klog.KObj(nil) - klog.KObjs(nil) + klog.KObjSlice(nil) klog.KRef("", "") klog.FromContext(nil) klog.TODO()