From 079aa77938290dbec820a3b021be6cbbc12ee20c Mon Sep 17 00:00:00 2001 From: Yun Date: Fri, 26 Jul 2024 17:52:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96error=E7=9A=84=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- format.go | 6 ++++++ loggerx_test.go | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/format.go b/format.go index 5e78085..1747b85 100644 --- a/format.go +++ b/format.go @@ -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" + for idx,val := range v { + if _, ok := val.(error); ok { + v[idx] = fmt.Sprintf("%+v", val) + } + } + fd := FormatData{ Time: nowTime, File: file + ":" + fmt.Sprintf("%d", line), diff --git a/loggerx_test.go b/loggerx_test.go index 27d6c81..ba95cfd 100644 --- a/loggerx_test.go +++ b/loggerx_test.go @@ -3,6 +3,7 @@ package loggerx_test import ( "bytes" "context" + "errors" "fmt" "testing" "time" @@ -38,6 +39,14 @@ func TestLogger(t *testing.T) { time.Sleep(time.Second * 5) } +func TestLogger2(t *testing.T) { + + err := errors.New("test error") + loggerx.Info(context.Background(), err) + +} + + type Print struct { }