diff --git a/benchmarks/zap_test.go b/benchmarks/zap_test.go index 92f7120ec..84784152c 100644 --- a/benchmarks/zap_test.go +++ b/benchmarks/zap_test.go @@ -116,7 +116,7 @@ func newZapLogger(lvl zapcore.Level) *zap.Logger { } func newSampledLogger(lvl zapcore.Level) *zap.Logger { - return zap.New(zapcore.NewSampler( + return zap.New(zapcore.NewSamplerWithOptions( newZapLogger(zap.DebugLevel).Core(), 100*time.Millisecond, 10, // first diff --git a/zapcore/sampler.go b/zapcore/sampler.go index dc11611ab..f1c60d0ac 100644 --- a/zapcore/sampler.go +++ b/zapcore/sampler.go @@ -159,7 +159,18 @@ type sampler struct { hook func(Entry, SamplingDecision) error } -// NewSampler is deprecated: use NewSamplerWithOptions. +// NewSampler 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 and message are seen during +// the same interval, every Mth message is logged and the rest are dropped. +// +// Keep in mind that zap's sampling implementation is optimized for speed over +// absolute precision; under load, each tick may be slightly over- or +// under-sampled. +// Deprecated: use NewSamplerWithOptions. func NewSampler(core Core, tick time.Duration, first, thereafter int) Core { return &sampler{ Core: core, diff --git a/zapcore/sampler_test.go b/zapcore/sampler_test.go index e4e2a9be2..71db0f9bd 100644 --- a/zapcore/sampler_test.go +++ b/zapcore/sampler_test.go @@ -37,7 +37,8 @@ import ( func fakeSampler(lvl LevelEnabler, tick time.Duration, first, thereafter int) (Core, *observer.ObservedLogs) { core, logs := observer.New(lvl) - core = NewSamplerWithOptions(core, tick, first, thereafter) + // Keep using deprecated constructor for cc. + core = NewSampler(core, tick, first, thereafter) return core, logs }