You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is possible to set a custom timestamp function with the TimesampFunc global variable. This is very useful especially for unit tests or when using zerolog in accelerated simulations.
Unfortunately, the BurstSampler uses time.Now() and not the TimesampFunc function to sample logs. Is there a reason why you did so?
My suggestion is to use the function in the file sampler.go:
func (s*BurstSampler) inc() uint32 {
now:=TimestampFunc().UnixNano() // <- here instead of now := time.Now().UnixNano()resetAt:=atomic.LoadInt64(&s.resetAt)
varcuint32ifnow>resetAt {
c=1atomic.StoreUint32(&s.counter, c)
newResetAt:=now+s.Period.Nanoseconds()
reset:=atomic.CompareAndSwapInt64(&s.resetAt, resetAt, newResetAt)
if!reset {
// Lost the race with another goroutine trying to reset.c=atomic.AddUint32(&s.counter, 1)
}
} else {
c=atomic.AddUint32(&s.counter, 1)
}
returnc
}
The text was updated successfully, but these errors were encountered:
It is possible to set a custom timestamp function with the
TimesampFunc
global variable. This is very useful especially for unit tests or when usingzerolog
in accelerated simulations.Unfortunately, the
BurstSampler
usestime.Now()
and not theTimesampFunc
function to sample logs. Is there a reason why you did so?My suggestion is to use the function in the file
sampler.go
:The text was updated successfully, but these errors were encountered: