Skip to content

Commit

Permalink
[libbeat] Remove global loggers from jsontransform (#18550) (#18645)
Browse files Browse the repository at this point in the history
(cherry picked from commit f54c6f5)
  • Loading branch information
kaiyan-sheng authored May 20, 2020
1 parent 63f8ae0 commit 24bb54e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions libbeat/common/jsontransform/jsonhelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

// WriteJSONKeys writes the json keys to the given event based on the overwriteKeys option and the addErrKey
func WriteJSONKeys(event *beat.Event, keys map[string]interface{}, overwriteKeys bool, addErrKey bool) {
logger := logp.NewLogger("jsonhelper")
if !overwriteKeys {
// @timestamp and @metadata fields are root-level fields. We remove them so they
// don't become part of event.Fields.
Expand All @@ -43,15 +44,15 @@ func WriteJSONKeys(event *beat.Event, keys map[string]interface{}, overwriteKeys
case "@timestamp":
vstr, ok := v.(string)
if !ok {
logp.Err("JSON: Won't overwrite @timestamp because value is not string")
logger.Error("JSON: Won't overwrite @timestamp because value is not string")
event.SetErrorWithOption(createJSONError("@timestamp not overwritten (not string)"), addErrKey)
continue
}

// @timestamp must be of format RFC3339
ts, err := time.Parse(time.RFC3339, vstr)
if err != nil {
logp.Err("JSON: Won't overwrite @timestamp because of parsing error: %v", err)
logger.Errorf("JSON: Won't overwrite @timestamp because of parsing error: %v", err)
event.SetErrorWithOption(createJSONError(fmt.Sprintf("@timestamp not overwritten (parse error on %s)", vstr)), addErrKey)
continue
}
Expand All @@ -74,12 +75,12 @@ func WriteJSONKeys(event *beat.Event, keys map[string]interface{}, overwriteKeys
case "type":
vstr, ok := v.(string)
if !ok {
logp.Err("JSON: Won't overwrite type because value is not string")
logger.Error("JSON: Won't overwrite type because value is not string")
event.SetErrorWithOption(createJSONError("type not overwritten (not string)"), addErrKey)
continue
}
if len(vstr) == 0 || vstr[0] == '_' {
logp.Err("JSON: Won't overwrite type because value is empty or starts with an underscore")
logger.Error("JSON: Won't overwrite type because value is empty or starts with an underscore")
event.SetErrorWithOption(createJSONError(fmt.Sprintf("type not overwritten (invalid value [%s])", vstr)), addErrKey)
continue
}
Expand Down

0 comments on commit 24bb54e

Please sign in to comment.