Add GetLevel method (#161)

This commit is contained in:
wangyuehong 2019-06-21 08:44:55 +09:00 committed by Olivier Poitrey
parent 9938a23cba
commit 60d4b07b61
2 changed files with 23 additions and 0 deletions

5
log.go
View File

@ -251,6 +251,11 @@ func (l Logger) Level(lvl Level) Logger {
return l
}
// GetLevel returns the current Level of l.
func (l Logger) GetLevel() Level {
return l.level
}
// Sample returns a logger with the s sampler.
func (l Logger) Sample(s Sampler) Logger {
l.sampler = s

View File

@ -453,6 +453,24 @@ func TestLevel(t *testing.T) {
})
}
func TestGetLevel(t *testing.T) {
levels := []Level{
DebugLevel,
InfoLevel,
WarnLevel,
ErrorLevel,
FatalLevel,
PanicLevel,
NoLevel,
Disabled,
}
for _, level := range levels {
if got, want := New(nil).Level(level).GetLevel(), level; got != want {
t.Errorf("GetLevel() = %v, want: %v", got, want)
}
}
}
func TestSampling(t *testing.T) {
out := &bytes.Buffer{}
log := New(out).Sample(&BasicSampler{N: 2})