diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2023-01-05 17:25:33 +0100 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2023-01-05 18:04:48 +0100 |
| commit | 5ffd0a395f7ef61b75b6ef4b625e78da7900e249 (patch) | |
| tree | a85cf3842d7fdf860b9b6f3e5ca04730635a5141 | |
| parent | 4e4879042a0737463cd3ca00e95d621d410921e4 (diff) | |
Logger: Do not interpret error string as format specifier argument
| -rw-r--r-- | client/client.go | 5 | ||||
| -rw-r--r-- | internal/log/log.go | 12 |
2 files changed, 9 insertions, 8 deletions
diff --git a/client/client.go b/client/client.go index b37c506..6dae665 100644 --- a/client/client.go +++ b/client/client.go @@ -2,6 +2,7 @@ package client import ( + "fmt" "strings" "github.com/eduvpn/eduvpn-common/internal/config" @@ -24,9 +25,9 @@ type ( func (c *Client) logError(err error) { // Logs the error with the same level/verbosity as the error if c.Debug { - c.Logger.Inheritf(err, "\nwith stacktrace: %s\n", err.(*errors.Error).ErrorStack()) + c.Logger.Inherit(err, fmt.Sprintf("\nwith stacktrace: %s\n", err.(*errors.Error).ErrorStack())) } else { - c.Logger.Inheritf(err, "") + c.Logger.Inherit(err, "") } } diff --git a/internal/log/log.go b/internal/log/log.go index 8b559fb..2fb2444 100644 --- a/internal/log/log.go +++ b/internal/log/log.go @@ -113,20 +113,20 @@ func (logger *FileLogger) Init(lvl Level, dir string) error { // Inheritf logs an error with a message and params using the error level verbosity of the error. // The message is always prefixed with the error. -func (logger *FileLogger) Inheritf(err error, msg string, params ...interface{}) { +func (logger *FileLogger) Inherit(err error, msg string) { if err == nil { return } - s := err.Error() + msg + s := "%s %s" switch GetErrorLevel(err) { case ErrInfo: - logger.Infof(s, params...) + logger.Infof(s, err.Error(), msg) case ErrWarning: - logger.Warningf(s, params...) + logger.Warningf(s, err.Error(), msg) case ErrOther: - logger.Errorf(s, params...) + logger.Errorf(s, err.Error(), msg) case ErrFatal: - logger.Fatalf(s, params...) + logger.Fatalf(s, err.Error(), msg) } } |
