mirror of
https://gitee.com/dromara/mayfly-go
synced 2026-04-20 11:15:18 +08:00
refactor: 日志堆栈描述调整
This commit is contained in:
@@ -2,6 +2,7 @@ package runtimex
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
@@ -21,7 +22,7 @@ func StatckStr(skip, nFrames int) string {
|
||||
i := 0
|
||||
for {
|
||||
frame, more := frames.Next()
|
||||
fmt.Fprintf(&b, "called from %s (%s:%d)\n\t", frame.Function, ParseFrameFile(frame.File), frame.Line)
|
||||
fmt.Fprintf(&b, "called from %s (%s:%d)\n\t", frame.Function, filepath.Base(frame.File), frame.Line)
|
||||
if !more {
|
||||
break
|
||||
}
|
||||
@@ -33,12 +34,3 @@ func StatckStr(skip, nFrames int) string {
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
|
||||
// 处理栈帧文件名
|
||||
func ParseFrameFile(frameFile string) string {
|
||||
// 尝试将完整路径如/usr/local/.../mayfly-go/server/pkg/starter/web-server.go切割为pkg/starter/web-server.go
|
||||
if ss := strings.Split(frameFile, "mayfly-go/server/"); len(ss) > 1 {
|
||||
return ss[1]
|
||||
}
|
||||
return frameFile
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user