Skip to content

Commit

Permalink
Merge pull request #27 from axiomhq/parse-json-logs
Browse files Browse the repository at this point in the history
parse json logs, duplicate record to message
  • Loading branch information
dasfmi authored Jan 11, 2024
2 parents ae88e5a + 19398fa commit f2e4a52
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
27 changes: 21 additions & 6 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,27 @@ func httpHandler(ax *flusher.Axiom, runtimeDone chan struct{}) http.HandlerFunc
e["_time"], e["time"] = e["time"], nil

if e["type"] == "function" {
// parse the record
matches := logLineRgx.FindStringSubmatch(e["record"].(string))
if len(matches) == 5 {
e["message"] = matches[4]
e["record"] = map[string]any{"requestId": matches[2], "message": e["record"], "timestamp": matches[1]}
e["level"] = strings.ToLower(matches[3])
e["message"] = e["record"]
if recordStr, ok := e["record"].(string); ok && len(recordStr) > 0 {
recordStr = strings.Trim(recordStr, "\n")
// parse the record
// first check if the record is a json object, if not parse it as a text log line
if recordStr[0] == '{' && recordStr[len(recordStr)-1] == '}' {
var record map[string]any
err = json.Unmarshal([]byte(recordStr), &record)
if err != nil {
logger.Error("Error unmarshalling record:", zap.Error(err))
// do not return, we want to continue processing the event
} else {
e["record"] = record
}
} else {
matches := logLineRgx.FindStringSubmatch(recordStr)
if len(matches) == 5 {
e["record"] = map[string]any{"requestId": matches[2], "message": matches[4], "timestamp": matches[1], "level": e["level"]}
e["level"] = strings.ToLower(matches[3])
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package version

// manually set constant version
const version string = "v9"
const version string = "v10"

// Get returns the Go module version of the axiom-go module.
func Get() string {
Expand Down

0 comments on commit f2e4a52

Please sign in to comment.