-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstack.go
More file actions
29 lines (24 loc) · 680 Bytes
/
stack.go
File metadata and controls
29 lines (24 loc) · 680 Bytes
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
package stackerr
import "fmt"
// Stack - contains stack info
type Stack struct {
File string
Line int
Function string
Context string
CallbackStack *Stack
}
// Sprint returns a pretty printed string of the Stacktrace ready for printng
func (s *Stack) Sprint() string {
stack := "Error Stacktrace:\n"
stackTrace := s
for stackTrace != nil {
if stackTrace.File != "" && stackTrace.Function != "" {
stack += fmt.Sprintf("-> %s:%d (%s) %s\n", stackTrace.File, stackTrace.Line, stackTrace.Function, stackTrace.Context)
} else {
stack += fmt.Sprint("-> out of context\n")
}
stackTrace = stackTrace.CallbackStack
}
return stack
}