Fix infinite recursion on unknown Level.String()

Using `%q` in the error string causes `MarshalText` to recurse (by calling String()).
This commit is contained in:
noushavandijk 2019-02-20 18:22:53 +01:00 committed by Richard Poirier
parent cdb2f3857c
commit 4f5fd631f1
2 changed files with 8 additions and 1 deletions

View File

@ -74,7 +74,7 @@ func (level Level) MarshalText() ([]byte, error) {
return []byte("panic"), nil return []byte("panic"), nil
} }
return nil, fmt.Errorf("not a valid lorus level %q", level) return nil, fmt.Errorf("not a valid logrus level %d", level)
} }
// A constant exposing all logging levels // A constant exposing all logging levels

View File

@ -521,6 +521,13 @@ func TestParseLevel(t *testing.T) {
assert.Equal(t, "not a valid logrus Level: \"invalid\"", err.Error()) assert.Equal(t, "not a valid logrus Level: \"invalid\"", err.Error())
} }
func TestLevelString(t *testing.T) {
var loggerlevel Level
loggerlevel = 32000
_ = loggerlevel.String()
}
func TestGetSetLevelRace(t *testing.T) { func TestGetSetLevelRace(t *testing.T) {
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {