From e27ea9f3707bedd5693a5d7e335c3f44efcb67e6 Mon Sep 17 00:00:00 2001 From: bryanqiu Date: Thu, 27 Apr 2023 11:16:31 +0800 Subject: [PATCH] v1.2.3 add error output when printpretty --- log.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/log.go b/log.go index 2a4867f..62b8df2 100644 --- a/log.go +++ b/log.go @@ -70,12 +70,22 @@ func (log *Logger) SetLogLevel(newlv logLevel) (oldlv logLevel) { } func (log *Logger) Print(prefix string, v interface{}) { - preety, _ := json.Marshal(v) - log.logwrite(DEBUG, 3, prefix+"%s\n", preety) + var str = "" + if pkg, err := json.Marshal(v); err != nil { + str = err.Error() + } else { + str = string(pkg) + } + log.logwrite(DEBUG, 3, prefix+"%s\n", str) } func (log *Logger) PrintPretty(prefix string, v interface{}) { - preety, _ := json.MarshalIndent(v, "==", " ") + var preety = "" + if pkg, err := json.MarshalIndent(v, "==", " "); err != nil { + preety = err.Error() + } else { + preety = string(pkg) + } log.logwrite(DEBUG, 3, prefix+"%s\n", preety) }