From 9e2a629b820110952f9f915fa3e997bb6d7b9e61 Mon Sep 17 00:00:00 2001 From: gezimbll Date: Fri, 3 Nov 2023 05:27:17 -0400 Subject: [PATCH] Add *log flag for logging ees events --- config/config_defaults.go | 2 +- ees/ees.go | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/config/config_defaults.go b/config/config_defaults.go index 5c71b72a2..2026535c7 100644 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -600,7 +600,7 @@ const CGRATES_CFG_JSON = ` }, // extra options for exporter "timezone": "", // timezone for timestamps where not specified <""|UTC|Local|$IANA_TZ_DB> "filters": [], // limit parsing based on the filters - "flags": [], // flags to influence the event processing + "flags": [], // flags to influence the event processing <*attributes|*log> "attribute_ids": [], // select Attribute profiles instead of discovering them "attribute_context": "", // context used to discover matching Attribute profiles "synchronous": false, // block processing until export has a result diff --git a/ees/ees.go b/ees/ees.go index f551b0c81..981a7cf2d 100644 --- a/ees/ees.go +++ b/ees/ees.go @@ -320,6 +320,29 @@ func ExportWithAttempts(exp EventExporter, eEv any, key string) (err error) { utils.EEs, exp.Cfg().ID, err.Error())) return } + + if exp.Cfg().Flags.GetBool(utils.MetaLog) { + var evLog string + switch c := eEv.(type) { + case []byte: + evLog = string(c) + case string: + evLog = c + case *HTTPPosterRequest: + evByt, cancast := c.Body.([]byte) + if cancast { + evLog = string(evByt) + break + } + evLog = utils.ToJSON(c.Body) + default: + evLog = utils.ToJSON(c) + } + utils.Logger.Info( + fmt.Sprintf("<%s> LOG, exporter <%s>, message: %s", + utils.EEs, exp.Cfg().ID, evLog)) + } + for i := 0; i < exp.Cfg().Attempts; i++ { if err = exp.ExportEvent(eEv, key); err == nil || err == utils.ErrDisconnected { // special error in case the exporter was closed