diff --git a/log/filter.go b/log/filter.go index a5d15c7eb..f410d2228 100644 --- a/log/filter.go +++ b/log/filter.go @@ -17,7 +17,8 @@ func NewFilter(next Logger, options ...Option) Logger { } // NewFilterByLevel wraps next and implements filtering based on a given level. -func NewFilterByLevel(next Logger, lvl string) Logger { +// Error is returned if level is not info, error or debug. +func NewFilterByLevel(next Logger, lvl string) (Logger, error) { var option Option switch lvl { case "info": @@ -27,9 +28,9 @@ func NewFilterByLevel(next Logger, lvl string) Logger { case "error": option = AllowError() default: - panic(fmt.Sprintf("Expected either \"info\", \"debug\" or \"error\" log level, given %v", lvl)) + return nil, fmt.Errorf("Expected either \"info\", \"debug\" or \"error\" log level, given %v", lvl) } - return NewFilter(next, option) + return NewFilter(next, option), nil } type filter struct { diff --git a/log/filter_test.go b/log/filter_test.go index cae10c145..edde86249 100644 --- a/log/filter_test.go +++ b/log/filter_test.go @@ -6,7 +6,6 @@ import ( "strings" "testing" - "github.com/stretchr/testify/assert" "github.com/tendermint/tmlibs/log" ) @@ -110,13 +109,12 @@ func TestLevelContext(t *testing.T) { } func TestNewFilterByLevel(t *testing.T) { - assert := assert.New(t) var logger log.Logger logger = log.NewNopLogger() - assert.NotPanics(func() { - logger = log.NewFilterByLevel(logger, "info") - }) - assert.Panics(func() { - logger = log.NewFilterByLevel(logger, "smth") - }) + if _, err := log.NewFilterByLevel(logger, "info"); err != nil { + t.Fatal(err) + } + if _, err := log.NewFilterByLevel(logger, "other"); err == nil { + t.Fatal(err) + } }