From 4f1a91faad91eb2d1fdab8bc8c7bf049355c3b9f Mon Sep 17 00:00:00 2001 From: Yun Date: Thu, 18 Apr 2024 12:02:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E4=B8=BAgithub=E7=9A=84=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- format.go | 8 +++++++- go.mod | 4 ++-- loggerx_test.go | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/format.go b/format.go index 356c1a1..68b8882 100644 --- a/format.go +++ b/format.go @@ -6,6 +6,7 @@ import ( "fmt" "path/filepath" "runtime" + "runtime/debug" "strings" "time" ) @@ -40,11 +41,15 @@ func (l *Logger) logger(ctx context.Context, event string, v ...any) { Content: string(by), TraceId: traceId, } + + if event == "error" { + fd.Stack = string(debug.Stack()) + } + fdb, _ := json.Marshal(fd) ff := []byte("\n[" + event + "]") fdb = append(ff, fdb...) - l.write(event, fdb) @@ -62,4 +67,5 @@ type FormatData struct { Gid string `json:"gid,omitempty"` Content string `json:"content,omitempty"` TraceId string `json:"traceId,omitempty"` + Stack string `json:"stack,omitempty"` } diff --git a/go.mod b/go.mod index 2500314..1537d1e 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ -module code.yun.ink/pkg/loggerx +module github.com/yuninks/loggerx -go 1.19 +go 1.20 require github.com/gin-gonic/gin v1.9.1 diff --git a/loggerx_test.go b/loggerx_test.go index a88380d..8ec371b 100644 --- a/loggerx_test.go +++ b/loggerx_test.go @@ -7,7 +7,7 @@ import ( "testing" "time" - "code.yun.ink/pkg/loggerx" + "github.com/yuninks/loggerx" ) // func TestMain(m *testing.M) {