Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zapcore: add warning as Level #1429

Merged
merged 3 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion zapcore/level.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (l *Level) unmarshalText(text []byte) bool {
*l = DebugLevel
case "info", "INFO", "": // make the zero value useful
*l = InfoLevel
case "warn", "WARN":
case "warn", "warning", "WARN":
*l = WarnLevel
case "error", "ERROR":
*l = ErrorLevel
Expand Down
10 changes: 10 additions & 0 deletions zapcore/level_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ func TestLevelText(t *testing.T) {
assert.NoError(t, err, `Unexpected error unmarshaling text %q to level.`, tt.text)
assert.Equal(t, tt.level, unmarshaled, `Text %q unmarshaled to an unexpected level.`, tt.text)
}

// Some logging libraries are using "warning" instead of "warn" as level indicator. Handle this case
// for cross compatability.
t.Run("unmarshal warning compatability", func(t *testing.T) {
var unmarshaled Level
input := []byte("warning")
err := unmarshaled.UnmarshalText(input)
assert.NoError(t, err, `Unexpected error unmarshaling text %q to level.`, string(input))
assert.Equal(t, WarnLevel, unmarshaled, `Text %q unmarshaled to an unexpected level.`, string(input))
})
}

func TestParseLevel(t *testing.T) {
Expand Down