-
Notifications
You must be signed in to change notification settings - Fork 976
Fix SeverityProcessor example #4541
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 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -195,19 +195,22 @@ type SeverityProcessor struct { | |||||||||||
| } | ||||||||||||
|
|
||||||||||||
| // OnEmit passes ctx and record to the wrapped sdklog.Processor | ||||||||||||
| // if the record's severity is greater than or equal to p.Min. | ||||||||||||
| // if the record's severity is greater than or equal to p.Min | ||||||||||||
| // or oustide the log.SeverityTrace1..log.SeverityFatal4 range. | ||||||||||||
| // Otherwise, the record is dropped (the wrapped processor is not invoked). | ||||||||||||
| func (p *SeverityProcessor) OnEmit(ctx context.Context, record *sdklog.Record) error { | ||||||||||||
| if record.Severity() != log.SeverityUndefined && record.Severity() < p.Min { | ||||||||||||
| sev := record.Severity() | ||||||||||||
| if sev >= log.SeverityTrace1 && sev <= log.SeverityFatal4 && sev < p.Min { | ||||||||||||
|
Contributor
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. Non-blocking, might be too go-specific: Should severity have an
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. I push for severity being treated as a number. It's always valid and always comparable, but you probably don't want to use <=0 values unless you're building something custom.
Member
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. @dashpole, I think that currently nothing in the spec says that values outside the 1..24 range are invalid. However, it might have be indeed the intention of the authors. I also do not want to make this PR too controversial.
Member
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 think that based on today's SIG discussion this could even be
Suggested change
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. I'd be in favor of treating Reasoning: However, It doesn't seem like there is a consensus around it. Maybe we can take discussion around 0 separately and/or make it configurable. The example, however, should be adjusted to force anyone copy-pasting it to think how they want to handle unspecified/0 value. I believe it's what @jack-berg suggested earlier as custom treatment for nulls. @trask suggested something like:
Suggested change
This would at least make someone copy-pasting the example to think how they want to handle 0. (PS: I spent a minute to triple-check this expression and I'm pretty sure you, my reader, did it too, that's exactly the reason why
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. For this non-normative example, I think I like the simplicity of
it provides a very reasonable default behavior, which is to drop logs that don't have any severity, and people can always build more complex logic to factor those logs in as needed |
||||||||||||
| return nil | ||||||||||||
| } | ||||||||||||
| return p.Processor.OnEmit(ctx, record) | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| // Enabled returns false if the severity is lower than p.Min. | ||||||||||||
| // Enabled returns false if the severity is lower than p.Min | ||||||||||||
| // and inside the log.SeverityTrace1..log.SeverityFatal4 range. | ||||||||||||
| func (p *SeverityProcessor) Enabled(ctx context.Context, param sdklog.EnabledParameters) bool { | ||||||||||||
| sev := param.Severity | ||||||||||||
| if sev != log.SeverityUndefined && sev < p.Min { | ||||||||||||
| if sev >= log.SeverityTrace1 && sev <= log.SeverityFatal4 && sev < p.Min { | ||||||||||||
|
Member
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 think that based on today's SIG discussion this could even be
Suggested change
|
||||||||||||
| return false | ||||||||||||
| } | ||||||||||||
| if fp, ok := p.Processor.(sdklog.FilterProcessor); ok { | ||||||||||||
|
|
||||||||||||
Uh oh!
There was an error while loading. Please reload this page.