Skip to content

Commit

Permalink
Reduce use of global loggers in libbeat/common (elastic#16149)
Browse files Browse the repository at this point in the history
* Reduce use of global loggers in libbeat/common

* review
  • Loading branch information
Steffen Siering authored Feb 19, 2020
1 parent 9143662 commit 3c78454
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions libbeat/common/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ import (
"github.com/elastic/beats/libbeat/logp"
)

const eventDebugSelector = "event"

var eventDebugf = logp.MakeDebug(eventDebugSelector)

var textMarshalerType = reflect.TypeOf((*encoding.TextMarshaler)(nil)).Elem()

type Float float64
Expand All @@ -46,12 +42,14 @@ type EventConverter interface {

// GenericEventConverter is used to normalize MapStr objects for publishing
type GenericEventConverter struct {
log *logp.Logger
keepNull bool
}

// NewGenericEventConverter creates an EventConverter with the given configuration options
func NewGenericEventConverter(keepNull bool) *GenericEventConverter {
return &GenericEventConverter{
log: logp.NewLogger("event"),
keepNull: keepNull,
}
}
Expand All @@ -64,7 +62,7 @@ func (e *GenericEventConverter) Convert(m MapStr) MapStr {
keys := make([]string, 0, 10)
event, errs := e.normalizeMap(m, keys...)
if len(errs) > 0 {
logp.Warn("Unsuccessful conversion to generic event: %v errors: %v, "+
e.log.Warnf("Unsuccessful conversion to generic event: %v errors: %v, "+
"event=%#v", len(errs), errs, m)
}
return event
Expand All @@ -85,8 +83,8 @@ func (e *GenericEventConverter) normalizeMap(m MapStr, keys ...string) (MapStr,

// Drop nil values from maps.
if !e.keepNull && v == nil {
if logp.IsDebug(eventDebugSelector) {
eventDebugf("Dropped nil value from event where key=%v", joinKeys(append(keys, key)...))
if e.log.IsDebug() {
e.log.Debugf("Dropped nil value from event where key=%v", joinKeys(append(keys, key)...))
}
continue
}
Expand Down

0 comments on commit 3c78454

Please sign in to comment.