Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix logcheck exit function
  • Loading branch information
luyou86 committed Sep 17, 2021
1 parent f8e668d commit f9de652
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions hack/tools/logcheck/main.go
Expand Up @@ -129,6 +129,7 @@ func isUnstructured(fName string) bool {
"Warning", "Warningf", "Warningln", "WarningDepth",
"Error", "Errorf", "Errorln", "ErrorDepth",
"Fatal", "Fatalf", "Fatalln", "FatalDepth",
"Exit", "Exitf", "Exitln", "ExitDepth",
}

for _, name := range unstrucured {
Expand Down
Expand Up @@ -60,4 +60,8 @@ func allowUnstructuredLogs() {
klog.Fatalf("test log")
klog.Fatalln("test log")
klog.FatalDepth(1, "test log")
klog.Exit("test log")
klog.ExitDepth(1, "test log")
klog.Exitln("test log")
klog.Exitf("test log")
}
Expand Up @@ -60,5 +60,8 @@ func doNotAllowUnstructuredLogs() {
klog.Fatalf("test log") // want `unstructured logging function "Fatalf" should not be used`
klog.Fatalln("test log") // want `unstructured logging function "Fatalln" should not be used`
klog.FatalDepth(1, "test log") // want `unstructured logging function "FatalDepth" should not be used`

klog.Exit("test log") // want `unstructured logging function "Exit" should not be used`
klog.Exitf("test log") // want `unstructured logging function "Exitf" should not be used`
klog.Exitln("test log") // want `unstructured logging function "Exitln" should not be used`
klog.ExitDepth(1, "test log") // want `unstructured logging function "ExitDepth" should not be used`
}
17 changes: 17 additions & 0 deletions hack/tools/logcheck/testdata/src/k8s.io/klog/v2/klog.go
Expand Up @@ -180,3 +180,20 @@ func Fatalln(args ...interface{}) {
// Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.
func Fatalf(format string, args ...interface{}) {
}

func Exit(args ...interface{}) {
}

// ExitDepth acts as Exit but uses depth to determine which call frame to log.
// ExitDepth(0, "msg") is the same as Exit("msg").
func ExitDepth(depth int, args ...interface{}) {
}

// Exitln logs to the FATAL, ERROR, WARNING, and INFO logs, then calls os.Exit(1).
func Exitln(args ...interface{}) {
}

// Exitf logs to the FATAL, ERROR, WARNING, and INFO logs, then calls os.Exit(1).
// Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.
func Exitf(format string, args ...interface{}) {
}

0 comments on commit f9de652

Please sign in to comment.