Skip to content

Commit

Permalink
zapcore: add warning as Level
Browse files Browse the repository at this point in the history
Some packages set their value for WarnLevel to "warning". For easier integration
add "warning" as accepted WarnLevel.

Example for a package that is using "warning":
https://github.com/sirupsen/logrus/blob/dd1b4c2e81afc5c255f216a722b012ed26be57df/logrus.go#L68

Signed-off-by: Florian Lehner <florian.lehner@elastic.co>
  • Loading branch information
florianl committed Apr 11, 2024
1 parent b15585b commit 3aefb87
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
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
3 changes: 2 additions & 1 deletion zapcore/level_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ func TestLevelText(t *testing.T) {
{"info", InfoLevel},
{"", InfoLevel}, // make the zero value useful
{"warn", WarnLevel},
{"warning", WarnLevel}, // compatibility handling for packages that emit "warning" instead of "warn"
{"error", ErrorLevel},
{"dpanic", DPanicLevel},
{"panic", PanicLevel},
{"fatal", FatalLevel},
}
for _, tt := range tests {
if tt.text != "" {
if tt.text != "" && tt.text != "warning" {
lvl := tt.level
marshaled, err := lvl.MarshalText()
assert.NoError(t, err, "Unexpected error marshaling level %v to text.", &lvl)
Expand Down

0 comments on commit 3aefb87

Please sign in to comment.