Skip to content

Commit

Permalink
Fix comment and add deprecated constructor in a different place for cc.
Browse files Browse the repository at this point in the history
  • Loading branch information
shirchen committed Apr 4, 2020
1 parent 25478e6 commit 5cc987e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion benchmarks/zap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion zapcore/sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion zapcore/sampler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 5cc987e

Please sign in to comment.