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

Check GlobalLevel for existing Zerolog instances #11

Open
rwngallego opened this issue Aug 21, 2021 · 2 comments
Open

Check GlobalLevel for existing Zerolog instances #11

rwngallego opened this issue Aug 21, 2021 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@rwngallego
Copy link

From the zerolog documentation:

// SetGlobalLevel sets the global override for log level. If this
// values is raised, all Loggers will use at least this value.
//
// To globally disable logs, set GlobalLevel to Disabled.

I've found a problem where the echo middleware didn't log requests using an existing zerolog instance because by default the level set in log is TraceLevel here https://github.com/rs/zerolog/blob/master/log.go#L213 which maps to zerolog.NoLevel or log.OFF in lecho. However, in zerolog we usually use the SetGlobalLevel to set the log level. One way would be to consider the zerolog.Level value when calculating the log level https://github.com/ziflex/lecho/blob/master/options.go#L19:

func newOptions(log zerolog.Logger, setters []Setter) *Options {
	elvl, _ := MatchZeroLevel(log.GetLevel())
...
}
@ziflex
Copy link
Owner

ziflex commented Aug 31, 2021

Hey, not sure I understand your problem with SetGlobalLevel.
Do you want lecho to compare levels of a given instance and global value before matching it?

@rwngallego
Copy link
Author

rwngallego commented Sep 1, 2021

Yes, in case the log instance has TraceLevel (which maps to log.OFF in lecho), check if maybe the library user has set the global level, because that is another way to set the log level in Zerolog: you can either set it per log instance (you already cover this) or globally with SetGlobalLevel (not supported yet).

Another alternative is to initially use what we have set using SetGlobalLevel and override it with whatever the log instance has that is different to TraceLevel, or the other way around.

@ziflex ziflex added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Dec 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants