@@ -91,12 +91,27 @@ func httpHandler(ax *flusher.Axiom, runtimeDone chan struct{}) http.HandlerFunc
91
91
e ["_time" ], e ["time" ] = e ["time" ], nil
92
92
93
93
if e ["type" ] == "function" {
94
- // parse the record
95
- matches := logLineRgx .FindStringSubmatch (e ["record" ].(string ))
96
- if len (matches ) == 5 {
97
- e ["message" ] = matches [4 ]
98
- e ["record" ] = map [string ]any {"requestId" : matches [2 ], "message" : e ["record" ], "timestamp" : matches [1 ]}
99
- e ["level" ] = strings .ToLower (matches [3 ])
94
+ e ["message" ] = e ["record" ]
95
+ if recordStr , ok := e ["record" ].(string ); ok && len (recordStr ) > 0 {
96
+ recordStr = strings .Trim (recordStr , "\n " )
97
+ // parse the record
98
+ // first check if the record is a json object, if not parse it as a text log line
99
+ if recordStr [0 ] == '{' && recordStr [len (recordStr )- 1 ] == '}' {
100
+ var record map [string ]any
101
+ err = json .Unmarshal ([]byte (recordStr ), & record )
102
+ if err != nil {
103
+ logger .Error ("Error unmarshalling record:" , zap .Error (err ))
104
+ // do not return, we want to continue processing the event
105
+ } else {
106
+ e ["record" ] = record
107
+ }
108
+ } else {
109
+ matches := logLineRgx .FindStringSubmatch (recordStr )
110
+ if len (matches ) == 5 {
111
+ e ["record" ] = map [string ]any {"requestId" : matches [2 ], "message" : matches [4 ], "timestamp" : matches [1 ], "level" : e ["level" ]}
112
+ e ["level" ] = strings .ToLower (matches [3 ])
113
+ }
114
+ }
100
115
}
101
116
}
102
117
0 commit comments