mirror of
https://github.com/amir20/dozzle.git
synced 2025-12-24 22:39:18 +01:00
fix: Coerce log level to lowercase when guessing in structured json (#2968)
This commit is contained in:
@@ -44,12 +44,12 @@ func guessLogLevel(logEvent *LogEvent) string {
|
||||
|
||||
case map[string]interface{}:
|
||||
if level, ok := value["level"].(string); ok {
|
||||
return level
|
||||
return strings.ToLower(level)
|
||||
}
|
||||
|
||||
case map[string]string:
|
||||
if level, ok := value["level"]; ok {
|
||||
return level
|
||||
return strings.ToLower(level)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
func TestGuessLogLevel(t *testing.T) {
|
||||
tests := []struct {
|
||||
input string
|
||||
input any
|
||||
expected string
|
||||
}{
|
||||
{"ERROR: Something went wrong", "error"},
|
||||
@@ -25,6 +25,10 @@ func TestGuessLogLevel(t *testing.T) {
|
||||
{"[foo] [ ERROR] Something went wrong", "error"},
|
||||
{"123 ERROR Something went wrong", "error"},
|
||||
{"123 Something went wrong", ""},
|
||||
{map[string]interface{}{"level": "info"}, "info"},
|
||||
{map[string]interface{}{"level": "INFO"}, "info"},
|
||||
{map[string]string{"level": "info"}, "info"},
|
||||
{map[string]string{"level": "INFO"}, "info"},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
||||
Reference in New Issue
Block a user