Skip to content

Commit c7ac885

Browse files
committed
♻️ refactor: update codebase #2
1 parent 05d3d7d commit c7ac885

3 files changed

Lines changed: 7 additions & 8 deletions

File tree

pkg/slogger/README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -812,11 +812,10 @@ Rate-limit identical log messages to prevent log storms during error spikes:
812812
```go
813813
log := 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

822821
Sampling is keyed on the exact message string. Each unique message maintains an

pkg/slogger/logger.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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
}

pkg/slogger/logger_internal_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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")

0 commit comments

Comments
 (0)