改为github的包

This commit is contained in:
Yun
2024-04-18 12:02:44 +08:00
parent b58849b5b2
commit 4f1a91faad
3 changed files with 10 additions and 4 deletions
+7 -1
View File
@@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"path/filepath" "path/filepath"
"runtime" "runtime"
"runtime/debug"
"strings" "strings"
"time" "time"
) )
@@ -40,12 +41,16 @@ func (l *Logger) logger(ctx context.Context, event string, v ...any) {
Content: string(by), Content: string(by),
TraceId: traceId, TraceId: traceId,
} }
if event == "error" {
fd.Stack = string(debug.Stack())
}
fdb, _ := json.Marshal(fd) fdb, _ := json.Marshal(fd)
ff := []byte("\n[" + event + "]") ff := []byte("\n[" + event + "]")
fdb = append(ff, fdb...) fdb = append(ff, fdb...)
l.write(event, fdb) l.write(event, fdb)
if l.option.errorToInfo && event == "error" { if l.option.errorToInfo && event == "error" {
@@ -62,4 +67,5 @@ type FormatData struct {
Gid string `json:"gid,omitempty"` Gid string `json:"gid,omitempty"`
Content string `json:"content,omitempty"` Content string `json:"content,omitempty"`
TraceId string `json:"traceId,omitempty"` TraceId string `json:"traceId,omitempty"`
Stack string `json:"stack,omitempty"`
} }
+2 -2
View File
@@ -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 require github.com/gin-gonic/gin v1.9.1
+1 -1
View File
@@ -7,7 +7,7 @@ import (
"testing" "testing"
"time" "time"
"code.yun.ink/pkg/loggerx" "github.com/yuninks/loggerx"
) )
// func TestMain(m *testing.M) { // func TestMain(m *testing.M) {