goroutine_recover.go 434 B

1234567891011121314151617181920
  1. package utils
  2. import (
  3. "git.aionnect.com/aionnect/go-common/utils/logger"
  4. "log"
  5. )
  6. func DefaultGoroutineRecover(l *logger.Logger, action string) {
  7. if err := recover(); err != nil {
  8. if e, ok := err.(error); ok {
  9. if nil != l {
  10. l.WithField("err", e.Error()).Error(action, " goroutine 异常")
  11. } else {
  12. log.Print(action, " goroutine 异常 ", e.Error())
  13. }
  14. stack := string(GetStack(3))
  15. println(stack)
  16. }
  17. }
  18. }