feat: optimize logx print error (#3649)

This commit is contained in:
MarkJoyMa
2023-10-19 08:46:52 -05:00
committed by GitHub
parent 50581c7f5c
commit 151768ef82
2 changed files with 22 additions and 2 deletions

View File

@@ -7,10 +7,13 @@ import (
"io"
"log"
"path"
"reflect"
"runtime/debug"
"sync"
"sync/atomic"
fatihcolor "github.com/fatih/color"
"github.com/zeromicro/go-zero/core/color"
)
@@ -332,7 +335,7 @@ func wrapLevelWithColor(level string) string {
func writeJson(writer io.Writer, info any) {
if content, err := json.Marshal(info); err != nil {
log.Println(err.Error())
log.Printf("err: %s, type: %s\n\n%s\n", err.Error(), reflect.TypeOf(info).Name(), debug.Stack())
} else if writer == nil {
log.Println(string(content))
} else {
@@ -384,7 +387,7 @@ func writePlainValue(writer io.Writer, level string, val any, fields ...string)
buf.WriteString(level)
buf.WriteByte(plainEncodingSep)
if err := json.NewEncoder(&buf).Encode(val); err != nil {
log.Println(err.Error())
log.Printf("err: %s, type: %s\n\n%s\n", err.Error(), reflect.TypeOf(val).Name(), debug.Stack())
return
}