Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix logcheck exit function #265

Merged
merged 1 commit into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions hack/tools/logcheck/main.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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")
}
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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{}) {
}