github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/utils/logging/samplers.go (about) 1 package logging 2 3 import ( 4 "time" 5 6 "github.com/rs/zerolog" 7 ) 8 9 type BurstSamplerOption func(*zerolog.BurstSampler) 10 11 // WithNextSampler adds a sampler that is applied after exceeding the burst limit 12 func WithNextSampler(sampler zerolog.Sampler) BurstSamplerOption { 13 return func(s *zerolog.BurstSampler) { 14 s.NextSampler = sampler 15 } 16 } 17 18 // BurstSampler returns a zerolog.BurstSampler with the provided burst and interval. 19 // Logs emitted beyond the burst limit are dropped 20 func BurstSampler(burst uint32, interval time.Duration, opts ...BurstSamplerOption) *zerolog.BurstSampler { 21 s := &zerolog.BurstSampler{ 22 Burst: burst, 23 Period: interval, 24 } 25 26 for _, opt := range opts { 27 opt(s) 28 } 29 30 return s 31 }