From 5788ab33d29122be72ad5d2e13edb65b5589e077 Mon Sep 17 00:00:00 2001 From: Justin Chadwell Date: Tue, 30 May 2023 10:00:24 +0100 Subject: [PATCH] logutil: print error from WithError if found Signed-off-by: Justin Chadwell --- util/logutil/format.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/util/logutil/format.go b/util/logutil/format.go index fcd73208..b392e2a6 100644 --- a/util/logutil/format.go +++ b/util/logutil/format.go @@ -1,6 +1,7 @@ package logutil import ( + "bytes" "fmt" "strings" @@ -12,5 +13,11 @@ type Formatter struct { } func (f *Formatter) Format(entry *logrus.Entry) ([]byte, error) { - return []byte(fmt.Sprintf("%s: %s\n", strings.ToUpper(entry.Level.String()), entry.Message)), nil + msg := bytes.NewBuffer(nil) + fmt.Fprintf(msg, "%s: %s", strings.ToUpper(entry.Level.String()), entry.Message) + if v, ok := entry.Data[logrus.ErrorKey]; ok { + fmt.Fprintf(msg, ": %v", v) + } + fmt.Fprintf(msg, "\n") + return msg.Bytes(), nil }