From 89f37c29b2ad52450d7a2075194c7b8af7c67ffe Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Wed, 16 Feb 2022 12:17:47 +0100 Subject: [PATCH] enhance and fix log calls Some of these changes are cosmetic (repeatedly calling klog.V instead of reusing the result), others address real issues: - Logging a message only above a certain verbosity threshold without recording that verbosity level (if klog.V().Enabled() { klog.Info... }): this matters when using a logging backend which records the verbosity level. - Passing a format string with parameters to a logging function that doesn't do string formatting. All of these locations where found by the enhanced logcheck tool from https://github.com/kubernetes/klog/pull/297. In some cases it reports false positives, but those can be suppressed with source code comments. Kubernetes-commit: edffc700a43e610f641907290a5152ca593bad79 --- logs/json/json_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/logs/json/json_test.go b/logs/json/json_test.go index a360d10c..1801bf9d 100644 --- a/logs/json/json_test.go +++ b/logs/json/json_test.go @@ -65,6 +65,7 @@ func TestZapLoggerInfo(t *testing.T) { var buffer bytes.Buffer writer := zapcore.AddSync(&buffer) sampleInfoLogger, _ := NewJSONLogger(writer, nil, nil) + // nolint:logcheck // The linter cannot and doesn't need to check the key/value pairs. sampleInfoLogger.Info(data.msg, data.keysValues...) logStr := buffer.String()