This commit is contained in:
2026-01-28 17:33:00 +03:00
parent c8814ca9ff
commit c7bc036d00
9 changed files with 357 additions and 270 deletions

60
traceback.go Normal file
View File

@@ -0,0 +1,60 @@
package slog
import (
"runtime"
"sort"
"strings"
)
func getTraceback() *MethodTraceback {
caller, _, _, _ := runtime.Caller(5)
details := runtime.FuncForPC(caller)
signature := details.Name()
path, line := details.FileLine(caller)
splitPath := strings.Split(path, "/")
splitSignature := strings.Split(signature, ".")
method := splitSignature[len(splitSignature)-1]
tb := &MethodTraceback{
Filename: splitPath[len(splitPath)-1],
FullPath: path,
Line: line,
Signature: signature,
Method: method,
}
return tb
}
func getFullTraceback(skip int) []*MethodTraceback {
pc := make([]uintptr, 15)
runtime.Callers(skip, pc)
list := make([]*MethodTraceback, 0)
frames := runtime.CallersFrames(pc)
for {
frame, more := frames.Next()
if !more {
break
}
details := runtime.FuncForPC(frame.PC)
signature := details.Name()
path, line := details.FileLine(frame.PC)
splitPath := strings.Split(path, "/")
splitSignature := strings.Split(signature, ".")
method := splitSignature[len(splitSignature)-1]
tb := &MethodTraceback{
Filename: splitPath[len(splitPath)-1],
FullPath: path,
Line: line,
Signature: signature,
Method: method,
}
list = append(list, tb)
}
sort.Slice(list, func(i, j int) bool {
return j < i
})
return list
}