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

Zap + logr == not very expressive, open to fixes? #972

Closed
thockin opened this issue Jun 28, 2021 · 3 comments · Fixed by #975
Closed

Zap + logr == not very expressive, open to fixes? #972

thockin opened this issue Jun 28, 2021 · 3 comments · Fixed by #975

Comments

@thockin
Copy link
Contributor

thockin commented Jun 28, 2021

One of my side-projects is https://github.com/go-logr/logr (an API for libraries to use to log) and alongside it lives the bridge to zap (https://github.com/go-logr/zapr).

Logr uses integer log levels - V(3) is "more debuggy" than V(2), which is more than V(1). Zap doesn't natively support that, but it seems to work, with a small number of caveats. So far I have found 1, actually.

zapcore/sampler.go does an indexed lookup by log level. When I use Logr verbose levels > 1 (which maps to Debug in zap) I get an out-of-bounds panic.

A quick hack of adding some number of extra debug levels (just add 100 indices to that array and accesses by +100) makes a trivial test pass with V(2), V(3), etc.

Before I really dig in, I wanted to see if this is something zap maintainers are willing to entertain ? I imagine it would ultimately manifest as a set of small changes here and there to handle the extra levels, plus tests. E.g. the level name already renders as "Level(-2)", so someone thought about this a little already.

@prashantv
Copy link
Collaborator

prashantv commented Jun 29, 2021

I don't think we want to add an arbitrary number of levels to the sampler array, since that's semi-support for custom levels (which aren't actually supported), and it works in some cases (if level is below some max value). There's also a slight cost for something unsupported.

However, I think avoiding panic is reasonable, so one option that we're open to is doing a "in-bounds" check before accessing the counts. We could then fail-open for unsupported levels, so they are not sampled.

What do you think of that approach?

@thockin
Copy link
Contributor Author

thockin commented Jun 29, 2021 via email

@prashantv
Copy link
Collaborator

PR would be great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants