Skip to content

Commit f9de652

Browse files
committed
Fix logcheck exit function
1 parent f8e668d commit f9de652

4 files changed

Lines changed: 26 additions & 1 deletion

File tree

hack/tools/logcheck/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ func isUnstructured(fName string) bool {
129129
"Warning", "Warningf", "Warningln", "WarningDepth",
130130
"Error", "Errorf", "Errorln", "ErrorDepth",
131131
"Fatal", "Fatalf", "Fatalln", "FatalDepth",
132+
"Exit", "Exitf", "Exitln", "ExitDepth",
132133
}
133134

134135
for _, name := range unstrucured {

hack/tools/logcheck/testdata/src/allowUnstructuredLogs/allowUnstructuredLogs.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,8 @@ func allowUnstructuredLogs() {
6060
klog.Fatalf("test log")
6161
klog.Fatalln("test log")
6262
klog.FatalDepth(1, "test log")
63+
klog.Exit("test log")
64+
klog.ExitDepth(1, "test log")
65+
klog.Exitln("test log")
66+
klog.Exitf("test log")
6367
}

hack/tools/logcheck/testdata/src/doNotAllowUnstructuredLogs/doNotAllowUnstructuredLogs.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,8 @@ func doNotAllowUnstructuredLogs() {
6060
klog.Fatalf("test log") // want `unstructured logging function "Fatalf" should not be used`
6161
klog.Fatalln("test log") // want `unstructured logging function "Fatalln" should not be used`
6262
klog.FatalDepth(1, "test log") // want `unstructured logging function "FatalDepth" should not be used`
63-
63+
klog.Exit("test log") // want `unstructured logging function "Exit" should not be used`
64+
klog.Exitf("test log") // want `unstructured logging function "Exitf" should not be used`
65+
klog.Exitln("test log") // want `unstructured logging function "Exitln" should not be used`
66+
klog.ExitDepth(1, "test log") // want `unstructured logging function "ExitDepth" should not be used`
6467
}

hack/tools/logcheck/testdata/src/k8s.io/klog/v2/klog.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,20 @@ func Fatalln(args ...interface{}) {
180180
// Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.
181181
func Fatalf(format string, args ...interface{}) {
182182
}
183+
184+
func Exit(args ...interface{}) {
185+
}
186+
187+
// ExitDepth acts as Exit but uses depth to determine which call frame to log.
188+
// ExitDepth(0, "msg") is the same as Exit("msg").
189+
func ExitDepth(depth int, args ...interface{}) {
190+
}
191+
192+
// Exitln logs to the FATAL, ERROR, WARNING, and INFO logs, then calls os.Exit(1).
193+
func Exitln(args ...interface{}) {
194+
}
195+
196+
// Exitf logs to the FATAL, ERROR, WARNING, and INFO logs, then calls os.Exit(1).
197+
// Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.
198+
func Exitf(format string, args ...interface{}) {
199+
}

0 commit comments

Comments
 (0)