fixed json access logger

This commit is contained in:
yusing 2024-12-18 08:01:58 +08:00
parent f683ab64ab
commit 783b352e3b
2 changed files with 6 additions and 1 deletions

View file

@ -41,7 +41,7 @@ func processMap[V any](cfg *FieldConfig, m map[string]V, redactedV V) map[string
return m
}
newMap := make(map[string]V)
newMap := make(map[string]V, len(m))
for k := range m {
var mode FieldMode
var ok bool

View file

@ -123,6 +123,11 @@ func (f JSONFormatter) Format(line *bytes.Buffer, req *http.Request, res *http.R
entry.Error = res.Status
}
if entry.ContentType != "" {
// try to get content type from request
entry.ContentType = req.Header.Get("Content-Type")
}
marshaller := json.NewEncoder(line)
err := marshaller.Encode(entry)
if err != nil {