From 82320944f9485ab493c4801e4bdf9f2a89be4eaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franc=C3=A9=20Wilke?= <francewilke@gmail.com> Date: Wed, 22 Jan 2025 11:16:59 +0200 Subject: [PATCH] Change ErrorWithMsg and ErrorWithFields to cater for formatting directives --- logs/logs.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/logs/logs.go b/logs/logs.go index 804988b..d9aaf9f 100644 --- a/logs/logs.go +++ b/logs/logs.go @@ -226,7 +226,7 @@ func Info(format string, a ...interface{}) { } } -func ErrorWithFields(fields map[string]interface{}, err error) { +func ErrorWithFields(err error, fields map[string]interface{}) { if disableLogging { return } @@ -242,17 +242,20 @@ func ErrorWithFields(fields map[string]interface{}, err error) { } } -func ErrorWithMsg(message string, err error) { +func ErrorWithMsg(err error, format string, a ...interface{}) { if disableLogging { return } + message := fmt.Sprintf(format, a...) + if err == nil { err = errors.Error(message) } - ErrorWithFields(map[string]interface{}{ + + ErrorWithFields(err, map[string]interface{}{ "message": message, - }, err) + }) } func ErrorMsg(format string, a ...interface{}) { @@ -262,7 +265,7 @@ func ErrorMsg(format string, a ...interface{}) { message := SanitiseLogs(fmt.Sprintf(format, a...)) - ErrorWithMsg(message, nil) + ErrorWithMsg(nil, message) } func Warn(format string, a ...interface{}) { @@ -280,7 +283,7 @@ func Warn(format string, a ...interface{}) { } } -func WarnWithFields(fields map[string]interface{}, err error) { +func WarnWithFields(err error, fields map[string]interface{}) { if disableLogging { return } -- GitLab