Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions levels.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ var levelStrings = map[string]Level{

// String implementation.
func (l Level) String() string {
// InvalidLevel (-1) and any unknown level above FatalLevel fall
// outside the levelNames array, so unguarded indexing used to
// panic with 'index out of range' whenever a zero-value or
// unexpected Level flowed into String - notably through
// MarshalJSON on a field that was never explicitly set (#75).
// Return "invalid" in those cases instead of crashing; the
// in-range levels still round-trip as before.
if l < DebugLevel || int(l) >= len(levelNames) {
return "invalid"
}
return levelNames[l]
}

Expand Down