Skip to content

Commit

Permalink
Feat: [GO] add log id as optional param to logs methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mhd999 committed Jul 5, 2023
1 parent 5a6fb2c commit 4b4d19d
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions rootle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
})
}
Expand Down

0 comments on commit 4b4d19d

Please sign in to comment.