logger에 RecoverAndErrorSmallStack 추가

This commit is contained in:
2025-05-14 16:14:35 +09:00
parent e53963d51e
commit 1170be24c0

View File

@ -127,3 +127,33 @@ func ErrorWithCallStack(err error) error {
frames: frames, frames: frames,
} }
} }
func ErrorSmallStack() {
buf := make([]byte, 1024)
n := runtime.Stack(buf, false)
if n < len(buf) {
buf = buf[:n]
}
Error(string(buf))
}
func RecoverAndErrorSmallStack(r any) any {
if r != nil {
pc := make([]uintptr, 10)
runtime.Callers(1, pc)
curframes := runtime.CallersFrames(pc)
var out []string
for {
frame, more := curframes.Next()
out = append(out, fmt.Sprintf("%s\n\t%s:%d", frame.Function, frame.File, frame.Line))
if !more {
break
}
}
Error(strings.Join(out, "\n"))
}
return r
}