mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-23 19:08:44 +00:00
avoid klog Info calls without verbosity
In the following code pattern, the log message will get logged with v=0 in JSON output although conceptually it has a higher verbosity: if klog.V(5).Enabled() { klog.Info("hello world") } Having the actual verbosity in the JSON output is relevant, for example for filtering out only the important info messages. The solution is to use klog.V(5).Info or something similar. Whether the outer if is necessary at all depends on how complex the parameters are. The return value of klog.V can be captured in a variable and be used multiple times to avoid the overhead for that function call and to avoid repeating the verbosity level.
This commit is contained in:
@@ -25,7 +25,7 @@ import (
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -435,8 +435,8 @@ func (rq *Controller) Sync(discoveryFunc NamespacedResourcesFunc, period time.Du
|
||||
defer rq.workerLock.Unlock()
|
||||
|
||||
// Something has changed, so track the new state and perform a sync.
|
||||
if klog.V(2).Enabled() {
|
||||
klog.Infof("syncing resource quota controller with updated resources from discovery: %s", printDiff(oldResources, newResources))
|
||||
if klogV := klog.V(2); klogV.Enabled() {
|
||||
klogV.Infof("syncing resource quota controller with updated resources from discovery: %s", printDiff(oldResources, newResources))
|
||||
}
|
||||
|
||||
// Perform the monitor resync and wait for controllers to report cache sync.
|
||||
|
Reference in New Issue
Block a user