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

Use same call depth for Enabled, Info, Error #218

Merged
merged 1 commit into from Sep 4, 2023

Conversation

thockin
Copy link
Contributor

@thockin thockin commented Sep 4, 2023

klog does stack unwinding in LogSink.Enabled to implement per-source code verbosity thresholds (-vmodule). This worked for logger.Info and logger.Error because the code was written such that it matches how logr is implemented (Logger.Info -> Logger.Enabled -> LogSink.Enabled).

It did not work for direct calls (if logger.Enabled) because then the call chain is Logger.Enabled -> LogSink.Enabled. Now it uses the same depth (as passed to LogSink.Init) for all paths to Enabled.

NOTE: callers who have worked around this bug will need to remove their workarounds.

Fixes #215
Alternative to #216

@thockin
Copy link
Contributor Author

thockin commented Sep 4, 2023

I took yours and went the other way - "fix the bug". It is "breaking" in that way, but it is clearly a bug that whomever stumbled over should have reported. Ahem :)

Thoughts?

klog does stack unwinding in `LogSink.Enabled` to implement per-source code
verbosity thresholds (`-vmodule`). This worked for `logger.Info` and
`logger.Error` because the code was written such that it matches how logr is
implemented (Logger.Info -> Logger.Enabled -> LogSink.Enabled).

It did not work for direct calls (`if logger.Enabled`) because then the call
chain is `Logger.Enabled -> LogSink.Enabled`.  Now it uses the same
depth (as passed to LogSink.Init) for all paths to Enabled.
@pohly
Copy link
Contributor

pohly commented Sep 4, 2023

NOTE: callers who have worked around this bug will need to remove their workarounds.

This has to be "NOTE: workarounds for this bug in implementations will need to be removed, and developers have to ensure that they combine recent logr only with implementations where that has been done"

I'm okay with doing it this way around. It's the "cleaner" solution, but also the more intrusive one.

Copy link
Contributor

@pohly pohly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with a modified klog, works. Let's use this solution.

@pohly pohly merged commit eb5bf2d into go-logr:master Sep 4, 2023
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enabled + stack unwinding
2 participants