start reworking exporters to be more composable

This commit is contained in:
2024-05-16 18:19:36 +02:00
parent ab5b70704d
commit fc92995cc8
10 changed files with 459 additions and 166 deletions

View File

@ -1,13 +1,28 @@
package code_location
import (
"runtime"
)
type CodeLocation struct {
FilePath string
FuncName string
LineNumber int
FilePath string
FuncName string
LineNumber int
ColumnNumber int
}
func FromStackTrace(...atDepth int) {
func FromStackTrace(atDepth ...int) CodeLocation {
skipLevelsInCallStack := 0
if len(atDepth) > 1 {
skipLevelsInCallStack = atDepth[0]
}
pc, file, line, _ := runtime.Caller(1 + skipLevelsInCallStack)
funcName := runtime.FuncForPC(pc).Name()
return CodeLocation{
FilePath: file,
LineNumber: line,
FuncName: funcName,
}
}