-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds more levels parsing like [ error] with spaces (#2441)
- Loading branch information
Showing
2 changed files
with
53 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package docker | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestGuessLogLevel(t *testing.T) { | ||
tests := []struct { | ||
input string | ||
expected string | ||
}{ | ||
{"ERROR: Something went wrong", "error"}, | ||
{"WARN: Something might be wrong", "warn"}, | ||
{"INFO: Something happened", "info"}, | ||
{"debug: Something happened", "debug"}, | ||
{"debug Something happened", "debug"}, | ||
{"TRACE: Something happened", "trace"}, | ||
{"FATAL: Something happened", "fatal"}, | ||
{"level=error Something went wrong", "error"}, | ||
{"[ERROR] Something went wrong", "error"}, | ||
{"[error] Something went wrong", "error"}, | ||
{"[ ERROR ] Something went wrong", "error"}, | ||
{"[error] Something went wrong", "error"}, | ||
{"123 ERROR Something went wrong", "error"}, | ||
{"123 Something went wrong", ""}, | ||
} | ||
|
||
for _, test := range tests { | ||
logEvent := &LogEvent{ | ||
Message: test.input, | ||
} | ||
if level := guessLogLevel(logEvent); level != test.expected { | ||
t.Errorf("guessLogLevel(%s) = %s, want %s", test.input, level, test.expected) | ||
} | ||
} | ||
|
||
} |