forked from peterlabuschagne/jettison
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trace.go
55 lines (46 loc) · 1.19 KB
/
trace.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package errors
import (
"fmt"
"testing"
"github.com/go-stack/stack"
"github.com/Zulzi/jettison/trace"
)
var (
configSet bool
traceConfig trace.StackConfig
)
func SetTraceConfig(config trace.StackConfig) {
if configSet {
panic(fmt.Sprintln("config has already been set", traceConfig, config))
}
traceConfig = config
configSet = true
}
func SetTraceConfigTesting(t testing.TB, config trace.StackConfig) {
old := traceConfig
t.Cleanup(func() {
traceConfig = old
})
traceConfig = config
}
var TestingConfig = trace.StackConfig{
TrimRuntime: true,
RemoveLambdas: true,
FormatStack: func(call stack.Call) string {
return fmt.Sprintf("%s %n", call, call)
},
FormatReference: func(call stack.Call) string {
return fmt.Sprintf("%s %n", call, call)
},
}
// getTrace will get the current binary and a stacktrace
// skip will omit a certain number of stack calls before getTrace
func getTrace(skip int) (string, []string) {
// Skip GetStackTrace and getTrace
return trace.CurrentBinary(), trace.GetStackTrace(skip+1, traceConfig)
}
// getSourceCode will get the current
// Skip getSourceCode
func getSourceCode(skip int) string {
return trace.GetSourceCodeRef(skip+1, traceConfig)
}