优化error的日志打印

This commit is contained in:
Yun
2024-07-26 17:52:32 +08:00
parent 1abd260929
commit 079aa77938
2 changed files with 15 additions and 0 deletions
+6
View File
@@ -32,6 +32,12 @@ func (l *Logger) logger(ctx context.Context, event string, v ...any) {
// writeStr := "[" + event + "]" + nowTime + " " + file + ":" + fmt.Sprintf("%d", line) + " " + funcName + " gid:" + getGID() + " " + traceId + " @data@: " + string(by) + "\n\n" // writeStr := "[" + event + "]" + nowTime + " " + file + ":" + fmt.Sprintf("%d", line) + " " + funcName + " gid:" + getGID() + " " + traceId + " @data@: " + string(by) + "\n\n"
for idx,val := range v {
if _, ok := val.(error); ok {
v[idx] = fmt.Sprintf("%+v", val)
}
}
fd := FormatData{ fd := FormatData{
Time: nowTime, Time: nowTime,
File: file + ":" + fmt.Sprintf("%d", line), File: file + ":" + fmt.Sprintf("%d", line),
+9
View File
@@ -3,6 +3,7 @@ package loggerx_test
import ( import (
"bytes" "bytes"
"context" "context"
"errors"
"fmt" "fmt"
"testing" "testing"
"time" "time"
@@ -38,6 +39,14 @@ func TestLogger(t *testing.T) {
time.Sleep(time.Second * 5) time.Sleep(time.Second * 5)
} }
func TestLogger2(t *testing.T) {
err := errors.New("test error")
loggerx.Info(context.Background(), err)
}
type Print struct { type Print struct {
} }