From a4ccd8f4e685062869bdc9d724c00fec5786cfb6 Mon Sep 17 00:00:00 2001 From: Jeff McCoy Date: Wed, 9 Feb 2022 06:43:17 -0600 Subject: [PATCH] Normalize trace references for debug/trace output --- cli/internal/message/message.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/cli/internal/message/message.go b/cli/internal/message/message.go index 0545543e09..371c065e5a 100644 --- a/cli/internal/message/message.go +++ b/cli/internal/message/message.go @@ -42,12 +42,12 @@ func init() { } } -func debugPrinter() *pterm.PrefixPrinter { - return pterm.Debug.WithShowLineNumber(logLevel > 2).WithLineNumberOffset(2) +func debugPrinter(offset int) *pterm.PrefixPrinter { + return pterm.Debug.WithShowLineNumber(logLevel > 2).WithLineNumberOffset(offset) } -func errorPrinter() *pterm.PrefixPrinter { - return pterm.Error.WithShowLineNumber(logLevel > 2).WithLineNumberOffset(2) +func errorPrinter(offset int) *pterm.PrefixPrinter { + return pterm.Error.WithShowLineNumber(logLevel > 2).WithLineNumberOffset(offset) } func SetLogLevel(lvl LogLevel) { @@ -62,19 +62,20 @@ func GetLogLevel() LogLevel { } func Debug(payload ...interface{}) { - debugPrinter().Println(payload...) + debugPrinter(1).Println(payload...) } func Debugf(format string, a ...interface{}) { - debugPrinter().Printfln(format, a...) + debugPrinter(2).Printfln(format, a...) } func Error(err interface{}, message string) { - Errorf(err, message) + debugPrinter(1).Println(err) + Warnf(message) } func Errorf(err interface{}, format string, a ...interface{}) { - Debug(err) + debugPrinter(1).Println(err) Warnf(format, a...) } @@ -88,15 +89,15 @@ func Warnf(format string, a ...interface{}) { } func Fatal(err interface{}, message string) { - Debug(err) - errorPrinter().Println(message) + debugPrinter(1).Println(err) + errorPrinter(1).Println(message) os.Exit(1) } func Fatalf(err interface{}, format string, a ...interface{}) { - Debug(err) + debugPrinter(1).Println(err) message := paragraph(format, a...) - errorPrinter().Println(message) + errorPrinter(1).Println(message) os.Exit(1) }