v1.2.3 add error output when printpretty

This commit is contained in:
bryanqiu 2023-04-27 11:16:31 +08:00
parent d93e63ab09
commit e27ea9f370

16
log.go
View File

@ -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)
}