1
This commit is contained in:
@ -15,7 +15,7 @@ func SafeGo(fn func()) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
// 记录 Goroutine ID、panic 信息和堆栈
|
||||
logger.Error(fmt.Sprintf("Recovered from panic in Goroutine %s: %v\nStack Trace:\n%s", getGoroutineID(), r, string(debug.Stack())))
|
||||
logger.Error(fmt.Sprintf("Recovered from panic in Goroutine %s: %v\nStack Trace:\n%s", GetGoroutineID(), r, string(debug.Stack())))
|
||||
}
|
||||
}()
|
||||
fn()
|
||||
@ -23,7 +23,7 @@ func SafeGo(fn func()) {
|
||||
}
|
||||
|
||||
// 获取 Goroutine ID
|
||||
func getGoroutineID() string {
|
||||
func GetGoroutineID() string {
|
||||
buf := make([]byte, 64)
|
||||
n := runtime.Stack(buf, false)
|
||||
stack := string(buf[:n])
|
||||
@ -36,7 +36,7 @@ func SafeGoParam[T any](fn func(T), param T) {
|
||||
go func() {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
logger.Error(fmt.Sprintf(" SafeGoParam Recovered from panic in Goroutine %s: %v\nStack Trace:\n%s", getGoroutineID(), r, string(debug.Stack())))
|
||||
logger.Error(fmt.Sprintf(" SafeGoParam Recovered from panic in Goroutine %s: %v\nStack Trace:\n%s", GetGoroutineID(), r, string(debug.Stack())))
|
||||
}
|
||||
}()
|
||||
fn(param) // 执行传入的函数
|
||||
|
||||
Reference in New Issue
Block a user