Skip to content

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

Merged
pohly merged 1 commit intogo-logr:masterfrom
thockin:calldepth_enabled_consistent
Sep 4, 2023
Merged

Use same call depth for Enabled, Info, Error#218
pohly merged 1 commit intogo-logr:masterfrom
thockin:calldepth_enabled_consistent

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.
@thockin thockin force-pushed the calldepth_enabled_consistent branch from 6754e58 to af7b2b7 Compare September 4, 2023 17:54
@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
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