MCPcopy
hub / github.com/uber-go/zap / NewSamplerWithOptions

Function NewSamplerWithOptions

zapcore/sampler.go:152–166  ·  view source on GitHub ↗

NewSamplerWithOptions creates a Core that samples incoming entries, which caps the CPU and I/O load of logging while attempting to preserve a representative subset of your logs. Zap samples by logging the first N entries with a given level and message each tick. If more Entries with the same level

(core Core, tick time.Duration, first, thereafter int, opts ...SamplerOption)

Source from the content-addressed store, hash-verified

150// absolute precision; under load, each tick may be slightly over- or
151// under-sampled.
152func NewSamplerWithOptions(core Core, tick time.Duration, first, thereafter int, opts ...SamplerOption) Core {
153 s := &sampler{
154 Core: core,
155 tick: tick,
156 counts: newCounters(),
157 first: uint64(first),
158 thereafter: uint64(thereafter),
159 hook: nopSamplingHook,
160 }
161 for _, opt := range opts {
162 opt.apply(s)
163 }
164
165 return s
166}
167
168type sampler struct {
169 Core

Callers 7

buildOptionsMethod · 0.92
newSampledLoggerFunction · 0.92
TestSamplerConcurrentFunction · 0.85
BenchmarkSampler_CheckFunction · 0.85
NewSamplerFunction · 0.85

Calls 2

newCountersFunction · 0.85
applyMethod · 0.65

Tested by 5

newSampledLoggerFunction · 0.74
TestSamplerConcurrentFunction · 0.68
BenchmarkSampler_CheckFunction · 0.68