You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 3 недеља
пре 3 недеља
пре 3 недеља
123456789101112131415161718192021222324
  1. package util
  2. import (
  3. "egg-im/pkg/logger"
  4. "fmt"
  5. "runtime"
  6. "go.uber.org/zap"
  7. )
  8. // RecoverPanic 恢复panic
  9. func RecoverPanic() {
  10. err := recover()
  11. if err != nil {
  12. logger.Logger.DPanic("panic", zap.Any("panic", err), zap.String("stack", GetStackInfo()))
  13. }
  14. }
  15. // GetStackInfo 获取Panic堆栈信息
  16. func GetStackInfo() string {
  17. buf := make([]byte, 4096)
  18. n := runtime.Stack(buf, false)
  19. return fmt.Sprintf("%s", buf[:n])
  20. }