代码拉取完成,页面将自动刷新
package log
import (
"errors"
"testing"
"github.com/no-src/log/content"
"github.com/no-src/log/formatter"
"github.com/no-src/log/level"
)
func TestSampleLogger(t *testing.T) {
testCases := []struct {
name string
sampleRate float64
formatter string
}{
{"sample rate less than zero", -1, formatter.TextFormatter},
{"sample rate equals zero", 0, formatter.TextFormatter},
{"normal sample rate", 0.5, formatter.TextFormatter},
{"sample rate equals one", 1, formatter.TextFormatter},
{"sample rate greater than one", 2, formatter.TextFormatter},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
InitDefaultLogger(NewDefaultSampleLogger(NewConsoleLogger(level.DebugLevel), tc.sampleRate).WithFormatter(formatter.New(tc.formatter)).WithTimeFormat(testTimeFormat))
testLogs(t)
Close()
})
}
}
func testSampleLogs() {
DefaultSampleLogger().WithFormatter(formatter.Default()).WithTimeFormat(content.DefaultLogTimeFormat())
DebugSample("[sample] %s %s, test debug log", "hello", "world")
InfoSample("[sample] %s %s, test info log", "hello", "world")
WarnSample("[sample] %s %s, test warn log", "hello", "world")
ErrorSample(errors.New("log err"), "[sample] %s %s,test error log", "hello", "world")
ErrorIfSample(errors.New("log err from ErrorIfSample"), "[sample] %s %s, test error log", "hello", "world")
ErrorIfSample(nil, "[sample] %s %s, this error log will not be printed", "hello", "world")
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。