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

flag set error : log to file or stderr #371

Closed
THMAIL opened this issue Feb 20, 2023 · 2 comments · Fixed by #376
Closed

flag set error : log to file or stderr #371

THMAIL opened this issue Feb 20, 2023 · 2 comments · Fixed by #376
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@THMAIL
Copy link

THMAIL commented Feb 20, 2023

/kind bug

What steps did you take and what happened:
I try to save log to local file with parameter :go run main.go -log_dir=logs -logtostderr=false
But errorLogs still will print to stderr!(infoLogs won't)
As the doc say "stderrthreshold : logs at or above this threshold go to stderr when writing to files and stderr (no effect when -logtostderr=true or -alsologtostderr=false.
So I tried go run main.go -log_dir=logs -logtostderr=false -alsologtostderr=true -stderrthreshold=2 and go run main.go -log_dir=logs -logtostderr=false -alsologtostderr=true -stderrthreshold=3, but it doesn't work at all.
The errorLogs still print to stderr.
So I analyzed the code of klog, finally I find that :

if alsoToStderr || l.alsoToStderr || s >= l.stderrThreshold.get() {
	os.Stderr.Write(data)
}

in klog.go file Line 20.
this code tell me I should set alsoToStderr to false, then the stderrThreshold can come into effect. This is contrary to what the documentation says!
I tried go run main.go -log_dir=logs -logtostderr=false -alsologtostderr=false -stderrthreshold=3. It worked ! the errorLog didn't print to stderr.

What did you expect to happen:
please fix this bug or just update the doc, it's up to you.

Anything else you would like to add:
[Miscellaneous information that will assist in solving the issue.]

@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Feb 20, 2023
@pohly
Copy link

pohly commented Feb 21, 2023

The code is the source of truth for this, because users might rely on this behavior.

Can you propose a PR which fixes the docs?

@logicalhan
Copy link
Member

/triage accepted
/assign @thockin

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Feb 23, 2023
@thockin thockin assigned pohly and unassigned thockin Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants