lecho icon indicating copy to clipboard operation
lecho copied to clipboard

Check GlobalLevel for existing Zerolog instances

Open rwngallego opened this issue 3 years ago • 2 comments

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())
...
}

rwngallego avatar Aug 21 '21 13:08 rwngallego

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?

ziflex avatar Aug 31 '21 15:08 ziflex

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.

rwngallego avatar Sep 01 '21 20:09 rwngallego