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

feat: adds support for LogFmt. fixes #2695 (#2705)

This commit is contained in:
Amir Raminfar
2024-01-17 14:01:40 -08:00
committed by GitHub
parent 9d2a8af435
commit ef359d339c
4 changed files with 30 additions and 0 deletions

1
go.mod
View File

@@ -39,6 +39,7 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/google/go-cmp v0.5.5 // indirect
github.com/kr/pretty v0.2.1 // indirect

2
go.sum
View File

@@ -37,6 +37,8 @@ github.com/go-chi/chi/v5 v5.0.11 h1:BnpYbFZ3T3S1WMpD79r7R5ThWX40TaFB7L31Y8xqSwA=
github.com/go-chi/chi/v5 v5.0.11/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/go-chi/jwtauth/v5 v5.3.0 h1:X7RKGks1lrVeIe2omGyz47pNaNjG2YmwlRN5UKhN8qg=
github.com/go-chi/jwtauth/v5 v5.3.0/go.mod h1:2PoGm/KbnzRN9ILY6HFZAI6fTnb1gEZAKogAyqkd6fY=
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=

View File

@@ -13,6 +13,7 @@ import (
"sync"
"time"
"github.com/go-logfmt/logfmt"
log "github.com/sirupsen/logrus"
)
@@ -177,6 +178,27 @@ func createEvent(message string, streamType StdType) *LogEvent {
} else {
logEvent.Message = data
}
} else if strings.Contains(message, "=") {
buffer := bufPool.Get().(*bytes.Buffer)
buffer.Reset()
defer bufPool.Put(buffer)
buffer.WriteString(message)
decoder := logfmt.NewDecoder(buffer)
data := make(map[string]string)
decoder.ScanRecord()
allValid := true
for decoder.ScanKeyval() {
key := decoder.Key()
value := decoder.Value()
if len(value) == 0 {
allValid = false
break
}
data[string(key)] = string(value)
}
if allValid && len(data) > 0 {
logEvent.Message = data
}
}
}
}

View File

@@ -45,6 +45,11 @@ func guessLogLevel(logEvent *LogEvent) string {
if level, ok := value["level"].(string); ok {
return level
}
case map[string]string:
if level, ok := value["level"]; ok {
return level
}
}
return ""