-
Notifications
You must be signed in to change notification settings - Fork 218
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
An extra line break was output #370
Comments
If you accept this problem, can you assign it to me? I am interested in solving this problem |
Which There's nothing in the |
I don't think it's a question of whether to delete it or not, it's not normal behavior for a log library to always delete the last newline (which itself needs to output newlines?) The problem with klog is that it adds newlines to all logs. For example, if you want to output "hello world", klog will process it as "hello world\n" and then call the logr implementation. It is normal to use the logr implementation because stdout or stderr require newlines, but that is only their Now the logic
He thought their ideal logic would be something like this
|
If it's not making the code flow more complex in klog, then I am open to merging a PR which solves this in klog. But if it's complex, then the question stands whether a solution elsewhere might be possible. |
/triage accepted |
/unassign |
/assign @aimuz |
klog always adds a newline to the msg. klog will work fine without klog. Set logr with klog.SetLogger, and klog will also pass the msg with the newline added to logr, which will result in an accidental newline being added. step1: klog.Info("hello world") step2: msg = msg + "\n" step3: stdout.W(msg) or logr.Info(msg[:len(msg)-1]) fix kubernetes#370 Signed-off-by: aimuz <[email protected]>
klog always adds a newline to the msg. klog will work fine without klog. Set logr with klog.SetLogger, and klog will also pass the msg with the newline added to logr, which will result in an accidental newline being added. step1: klog.Info("hello world") step2: msg = msg + "\n" step3: stdout.W(msg) or logr.Info(msg[:len(msg)-1]) fix kubernetes#370 Signed-off-by: aimuz <[email protected]>
klog always adds a newline to the msg. klog will work fine without klog. Set logr with klog.SetLogger, and klog will also pass the msg with the newline added to logr, which will result in an accidental newline being added. step1: klog.Info("hello world") step2: msg = msg + "\n" step3: stdout.W(msg) or logr.Info(msg[:len(msg)-1]) fix kubernetes#370 Signed-off-by: aimuz <[email protected]>
klog always adds a newline to the msg. klog will work fine without klog. Set logr with klog.SetLogger, and klog will also pass the msg with the newline added to logr, which will result in an accidental newline being added. step1: klog.Info("hello world") step2: msg = msg + "\n" step3: stdout.W(msg) or logr.Info(msg[:len(msg)-1]) fix kubernetes#370 Signed-off-by: aimuz <[email protected]>
klog always adds a newline to the msg. klog will work fine without klog. Set logr with klog.SetLogger, and klog will also pass the msg with the newline added to logr, which will result in an accidental newline being added. step1: klog.Info("hello world") step2: msg = msg + "\n" step3: stdout.W(msg) or logr.Info(msg[:len(msg)-1]) fix kubernetes#370 Signed-off-by: aimuz <[email protected]>
/kind bug
What steps did you take and what happened:
[A clear and concise description of what the bug is.]
This is a log without SetLogger
This is set by SetLogger
They output a new line between them. After my investigation, I found that klog adds a new line at the end of the msg, but for the log output by the logr, the new line will be automatically added.
He can work normally under stdout, because stdout needs this newline
https://github.com/kubernetes/klog/blob/main/klog.go#L729
What did you expect to happen:
Do not add new lines when using logr
Anything else you would like to add:
[Miscellaneous information that will assist in solving the issue.]
The text was updated successfully, but these errors were encountered: