MCPcopy
hub / github.com/rs/zerolog / TestDisableSampling

Function TestDisableSampling

log_test.go:815–835  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

813}
814
815func TestDisableSampling(t *testing.T) {
816 // Save original state
817 original := samplingDisabled()
818 defer DisableSampling(original)
819
820 out := &bytes.Buffer{}
821 log := New(out).Sample(&BasicSampler{N: 2})
822
823 // Enable sampling disable
824 DisableSampling(true)
825
826 log.Log().Int("i", 1).Msg("")
827 log.Log().Int("i", 2).Msg("")
828 log.Log().Int("i", 3).Msg("")
829 log.Log().Int("i", 4).Msg("")
830
831 // All messages should be logged since sampling is disabled
832 if got, want := decodeIfBinaryToString(out.Bytes()), "{\"i\":1}\n{\"i\":2}\n{\"i\":3}\n{\"i\":4}\n"; got != want {
833 t.Errorf("invalid log output:\ngot: %v\nwant: %v", got, want)
834 }
835}
836
837func TestDiscard(t *testing.T) {
838 out := &bytes.Buffer{}

Callers

nothing calls this directly

Calls 9

samplingDisabledFunction · 0.85
DisableSamplingFunction · 0.85
NewFunction · 0.85
MsgMethod · 0.80
decodeIfBinaryToStringFunction · 0.70
SampleMethod · 0.65
LogMethod · 0.65
IntMethod · 0.45
BytesMethod · 0.45

Tested by

no test coverage detected