-
Notifications
You must be signed in to change notification settings - Fork 226
Modify output method of loggingT to handle Logger/InfoLogger correctly #118
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -812,14 +812,17 @@ func (l *loggingT) output(s severity, log logr.InfoLogger, buf *buffer, file str | |
| } | ||
| } | ||
| data := buf.Bytes() | ||
| if log != nil { | ||
| // TODO: set 'severity' and caller information as structured log info | ||
| // keysAndValues := []interface{}{"severity", severityName[s], "file", file, "line", line} | ||
| // In later version, we should check argument s is either errorLog or infoLog. | ||
| // However for now, as backward compatibility, all s other than errorLog goes to l.logr.Info(). | ||
| // if l.logr != nil && (s == errorLog || s == infoLog) { | ||
| if l.logr != nil { | ||
| if s == errorLog { | ||
| l.logr.Error(nil, string(data)) | ||
| l.logr.Error(nil, string(data), "severity", severityName[s], "file", file, "line", line) | ||
| } else { | ||
| log.Info(string(data)) | ||
| l.logr.Info(string(data), "severity", severityName[s], "file", file, "line", line) | ||
| } | ||
| } else if log != nil && s == infoLog { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should technically never be possible to get into a state where This logic looks right to me :) just trying to validate my own assumptions!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @munnerz . Yes, that is underlying idea of this line. Ideally, it should not happen.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. If
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, as you said, if As I wrote in
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There are log levels in between (e.g. warning) that do not have direct equivalents in a logr world (as logr only has levels). The thinking is to treat any un-levelled log message that specifies a non-info level severity as an Info message and pass along the Mostly there wasn't clear consensus as to what 'keys' should be used and what the onus is on implementors of the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand why k/v isn't added. It's hard problem, until some set of standard keys is established. Thanks! |
||
| log.Info(string(data), "severity", severityName[s], "file", file, "line", line) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the above branching looks mostly correct to me, but i pinged the #klog channel of k8s slack for more reviewers.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! |
||
| } else if l.toStderr { | ||
| os.Stderr.Write(data) | ||
| } else { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.