Skip to content

comment docs are out of date, recommend code style that kubernetes-sigs/logtools warns about #405

@danwinship

Description

@danwinship

I tried doing

if klog.V(9) {
	klog.InfoS("Running nftables transaction", "transaction", tx.String())
}

which I know used to work, but apparently now it doesn't, so I checked the klog sources, and klog.go says:

// See the documentation for the V function for an explanation of these examples:
//
//	if klog.V(2) {
//		klog.Info("Starting transaction...")
//	}

Ignoring the comment, I dug further and found the Enabled() function and then it compiled, but it turns out that golangci-lint still doesn't like it:

ERROR: pkg/proxy/nftables/proxier.go:1617:2: the result of klog.V should be stored in a variable and then be used multiple times: if klogV := klog.V(); klogV.Enabled() { ... klogV.Info ... } (logcheck)
ERROR: 	if klog.V(9).Enabled() {
ERROR: 	^ 

(which, FTR, is a terrible API though I don't have any ideas on fixing it)

The whole introductory doc comment in klog.go needs a rewrite/update, which maybe ought to be copied to the README?

/kind documentation

Metadata

Metadata

Assignees

Labels

kind/documentationCategorizes issue or PR as related to documentation.priority/backlogHigher priority than priority/awaiting-more-evidence.triage/acceptedIndicates an issue or PR is ready to be actively worked on.

Type

No type

Projects

Status

Needs Triage

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions