From 4b4d19de3edb8b4a5201e779cfd809d5465cc41d Mon Sep 17 00:00:00 2001 From: Mohamad al moualem Date: Wed, 5 Jul 2023 15:07:29 +0200 Subject: [PATCH] Feat: [GO] add log id as optional param to logs methods --- rootle.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/rootle.go b/rootle.go index 52bf58e..bc11f4c 100644 --- a/rootle.go +++ b/rootle.go @@ -145,9 +145,13 @@ func GetRootle() *Config { return localRootle } -func logMessage(c Config, message any, level string, event *string, downstream *Downstream, stackTrace *string, code *int, callback func(logJSON string)) { +func logMessage(c Config, id []string, message any, level string, event *string, downstream *Downstream, stackTrace *string, code *int, callback func(logJSON string)) { + var idArg = *c.ID + if len(id) > 0 { + idArg = id[0] + } rootleLog := Log{ - ID: *c.ID, + ID: idArg, Application: *c.Application, Timestamp: time.Now().Unix(), Message: message, @@ -163,20 +167,20 @@ func logMessage(c Config, message any, level string, event *string, downstream * callback(string(jsonLog)) } -func (c *Config) Info(message any) { - logMessage(*c, message, "INFO", nil, nil, nil, nil, func(logJSON string) { +func (c *Config) Info(message any, id ...string) { + logMessage(*c, id, message, "INFO", nil, nil, nil, nil, func(logJSON string) { log.Println(logJSON) }) } -func (c *Config) Warn(message any) { - logMessage(*c, message, "WARN", nil, nil, nil, nil, func(logJSON string) { +func (c *Config) Warn(message any, id ...string) { + logMessage(*c, id, message, "WARN", nil, nil, nil, nil, func(logJSON string) { log.Println(logJSON) }) } -func (c *Config) Error(message any, event *string, downstream *Downstream, stackTrace *string, code *int) { - logMessage(*c, message, "ERROR", event, downstream, stackTrace, code, func(logJSON string) { +func (c *Config) Error(message any, event *string, downstream *Downstream, stackTrace *string, code *int, id ...string) { + logMessage(*c, id, message, "ERROR", event, downstream, stackTrace, code, func(logJSON string) { log.Println(logJSON) }) }