refactor: 日志堆栈描述调整

This commit is contained in:
meilin.huang
2023-09-03 13:04:29 +08:00
parent 899a3a8243
commit 649116a0b8
5 changed files with 14 additions and 27 deletions

View File

@@ -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
}