Skip to content

Commit

Permalink
Fix infinite recursion on unknown Level.String()
Browse files Browse the repository at this point in the history
Using `%q` in the error string causes `MarshalText` to recurse (by calling String()).
  • Loading branch information
noushavandijk authored and richpoirier committed Feb 20, 2019
1 parent f592aff commit 06ce2d9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion logrus.go
Expand Up @@ -74,7 +74,7 @@ func (level Level) MarshalText() ([]byte, error) {
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
Expand Down
7 changes: 7 additions & 0 deletions logrus_test.go
Expand Up @@ -521,6 +521,13 @@ func TestParseLevel(t *testing.T) {
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) {
wg := sync.WaitGroup{}
for i := 0; i < 100; i++ {
Expand Down

0 comments on commit 06ce2d9

Please sign in to comment.