goroutine_recover.go 410 B

123456789101112131415161718
  1. package utils
  2. import (
  3. "git.haoqitour.com/haoqi/go-common/utils/logger"
  4. "github.com/prometheus/common/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.Warn(action, " goroutine 异常 ", e.Error())
  13. }
  14. }
  15. }
  16. }