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

Allow more verbose logs (option 1) #23

Closed
wants to merge 3 commits into from

Conversation

tonglil
Copy link

@tonglil tonglil commented Jan 27, 2023

Closes #20.

It looks like @thockin made a PR to Zerolog to allow arbitrary levels. I updated this library to allow these more verbose levels in 2 approaches.

This is similar to https://github.com/go-logr/zapr#increasing-verbosity.


I prefer this approach, where the specified Zerolog level matches logr's V() levels numerically.

This is clear that setting Zerolog to named levels shows level names, while numerical levels (-3) shows their "negatively corresponding" V() logs (V(3)):

	l := zerolog.Level(-3)
	zerolog.SetGlobalLevel(l)
	zl := zerolog.New(os.Stdout).Level(l)
	log := zerologr.New(&zl)
	log.Info("Info you should see this")
	log.V(1).Info("v1 you should see this")
	log.V(2).Info("v2 you should see this")
	log.V(3).Info("v3 you should see this")
	log.V(4).Info("v4 you should NOT see this")

Yields:

{"level":"info","v":0,"message":"Info you should see this"}
{"level":"debug","v":1,"message":"v1 you should see this"}
{"level":"trace","v":2,"message":"v2 you should see this"}
{"level":"-3","v":3,"message":"v3 you should see this"}

@hn8
Copy link
Contributor

hn8 commented Jan 28, 2023

@tonglil Option 2 is less confusing. Otherwise, zerolog level -2 is not mapped to any logr level. Since zerolog.TraceLevel is -1, -2 would be next level someone might try first.

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.

Cannot log with verbosity > 2
2 participants