Documentation ¶
Index ¶
- Variables
- func GetCallStack(size int) string
- func GetCaller(skip int) string
- func GetCallerFuncFileLine(skip int) (caller string, file string, line int)
- func GetEIP(uintptr) uintptr
- func GetShortCallerFuncFileLine(skip int) (caller string, file string, line int)
- func RecoverFromPanic(err error) error
- type Panic
Examples ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func GetCallStack ¶
GetCallStack Same as stdlib http server code. Manually allocate stack trace buffer size to prevent excessively large logs
func GetCaller ¶
GetCaller returns the caller of the function that calls it. The argument skip is the number of stack frames to skip before recording in pc, with 0 identifying the frame for Callers itself and 1 identifying the caller of Callers.
Example ¶
package main import ( "fmt" "github.com/searKing/golang/go/runtime" ) func main() { caller := runtime.GetCaller(1) fmt.Print(caller) }
Output: github.com/searKing/golang/go/runtime_test.ExampleGetCaller
func GetCallerFuncFileLine ¶ added in v0.0.130
GetCallerFuncFileLine returns the __FUNCTION__, __FILE__ and __LINE__ of the function that calls it. The argument skip is the number of stack frames to skip before recording in pc, with 0 identifying the frame for Callers itself and 1 identifying the caller of Callers.
func GetShortCallerFuncFileLine ¶ added in v0.0.130
GetShortCallerFuncFileLine returns the short form of GetCallerFuncFileLine. The argument skip is the number of stack frames to skip before recording in pc, with 0 identifying the frame for Callers itself and 1 identifying the caller of Callers.
Example ¶
package main import ( "fmt" "github.com/searKing/golang/go/runtime" ) func main() { caller, file, line := runtime.GetShortCallerFuncFileLine(1) fmt.Printf("%s() %s:%d", caller, file, line) }
Output: ExampleGetShortCallerFuncFileLine() run_example.go:63
func RecoverFromPanic ¶
RecoverFromPanic replaces the specified error with an error containing the original error, and the call tree when a panic occurs. This enables error handlers to handle errors and panics the same way.
Types ¶
type Panic ¶
type Panic struct { // IgnoreCrash controls the behavior of Recover and now defaults false. // if false, crash immediately, rather than eating panics. IgnoreCrash bool // PanicHandlers for something like logging the panic message, shutting down go routines gracefully. PanicHandlers []func(interface{}) }
Panic simply catches a panic and logs an error. Meant to be called via defer. Additional context-specific handlers can be provided, and will be called in case of panic.
func HandlePanicWith ¶ added in v0.0.95
func HandlePanicWith(handlers ...func(interface{})) Panic