mirror of
https://github.com/amir20/dozzle.git
synced 2026-01-04 12:05:07 +01:00
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"hash/fnv"
|
||||
"io"
|
||||
@@ -164,7 +165,12 @@ func createEvent(message string, streamType StdType) *LogEvent {
|
||||
if json.Valid([]byte(message)) {
|
||||
var data map[string]interface{}
|
||||
if err := json.Unmarshal([]byte(message), &data); err != nil {
|
||||
log.Warnf("unable to parse json logs - error was \"%v\" while trying unmarshal \"%v\"", err.Error(), message)
|
||||
var jsonErr *json.UnmarshalTypeError
|
||||
if errors.As(err, &jsonErr) {
|
||||
if jsonErr.Value == "string" {
|
||||
log.Warnf("unable to parse json logs - error was \"%v\" while trying unmarshal \"%v\"", err.Error(), message)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logEvent.Message = data
|
||||
}
|
||||
|
||||
@@ -117,6 +117,15 @@ func Test_createEvent(t *testing.T) {
|
||||
Message: "{\"key\"}",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "invalid json message",
|
||||
args: args{
|
||||
message: "2020-05-13T18:55:37.772853839Z 123",
|
||||
},
|
||||
want: &LogEvent{
|
||||
Message: "123",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user