1
0
mirror of https://github.com/amir20/dozzle.git synced 2025-12-24 14:31:44 +01:00

feat: removes colors to find the level (#2218)

This commit is contained in:
Amir Raminfar
2023-05-25 10:21:07 -07:00
committed by GitHub
parent a2d208adf7
commit ad46d53ef2

View File

@@ -124,14 +124,15 @@ func (g *eventGenerator) consume() {
}
}
var NON_ASCII_REGEX = regexp.MustCompile("^[^a-zA-z ]+[^ewidtf]?")
var KEY_VALUE_REGEX = regexp.MustCompile(`level=(\w+)`)
var ANSI_COLOR_REGEX = regexp.MustCompile(`\x1b\[[0-9;]*m`)
func guessLogLevel(logEvent *LogEvent) string {
switch value := logEvent.Message.(type) {
case string:
levels := []string{"error", "warn", "info", "debug", "trace", "fatal"}
stripped := NON_ASCII_REGEX.ReplaceAllString(value, "")
stripped := ANSI_COLOR_REGEX.ReplaceAllString(value, "") // remove ansi color codes
log.Debugf("colors stripped: %s", stripped)
for _, level := range levels {
if match, _ := regexp.MatchString("(?i)^"+level+"[^a-z]", stripped); match {
return level