golang-im聊天
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.
 
 
 
 

25 lines
430 B

  1. package util
  2. import (
  3. "fmt"
  4. "gim/pkg/logger"
  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. }