File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -812,11 +812,10 @@ Rate-limit identical log messages to prevent log storms during error spikes:
812812``` go
813813log := slogger.NewLogger ().
814814 WithLevel (slogger.InfoLevel ).
815- WithSampling (slogger.SamplingOptions {
816- First : 10 , // log the first 10 identical messages per second
817- Period : time.Second , // sliding window duration
818- Thereafter : 100 , // then log every 100th message
819- })
815+ WithSampling (slogger.NewSamplingOptions ().
816+ WithFirst (10 ). // log the first 10 identical messages per second
817+ WithPeriod (time.Second ). // sliding window duration
818+ WithThereafter (100 )) // then log every 100th message
820819```
821820
822821Sampling is keyed on the exact message string. Each unique message maintains an
Original file line number Diff line number Diff line change @@ -424,9 +424,9 @@ func (l *Logger) WithCallerSkip(skip int) *Logger {
424424// Returns:
425425//
426426// the receiver *Logger, enabling method chaining.
427- func (l * Logger ) WithSampling (opts SamplingOptions ) * Logger {
427+ func (l * Logger ) WithSampling (opts * SamplingOptions ) * Logger {
428428 l .mu .Lock ()
429- l .sampling = newSampler (opts )
429+ l .sampling = newSampler (* opts )
430430 l .mu .Unlock ()
431431 return l
432432}
Original file line number Diff line number Diff line change @@ -778,7 +778,7 @@ func TestLogger_WithSampling(t *testing.T) {
778778 WithOutput (& buf ).
779779 WithLevel (TraceLevel ).
780780 WithFormatter (NewTextFormatter (& buf ).WithDisableColor ()).
781- WithSampling (SamplingOptions { first : 1 , thereafter : 0 , period : time .Hour } )
781+ WithSampling (NewSamplingOptions (). WithFirst ( 1 ). WithThereafter ( 0 ). WithPeriod ( time .Hour ) )
782782
783783 // First message should be logged
784784 log .Info ("test sampling" )
You can’t perform that action at this time.
0 commit comments