Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ArgSentryDSN = &cobraviper.StringArgument{
ArgumentName: "sentry-dsn",
EnvName: "SENTRY_DSN",
Usage: "The sentry DSN for reporting command error",
}
View Source
var RunEWrap = func(binderGetter BinderGetter, do InputRunEFunc) OutputRunEFunc { return func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() binder := binderGetter() sentryDSN := binder.GetString(cmd, ArgSentryDSN) var sentryHub *sentry.Hub if sentryDSN != "" { sentryHub, err = sentryutil.NewHub(sentryDSN) if err != nil { return err } } ctx = WithHub(ctx, sentryHub) loggerFactory := NewLoggerFactory(sentryHub) logger := loggerFactory.New("cobra-sentry"). WithField("cmd_name", cmd.Name()). WithField("cmd_short", cmd.Short) defer func() { e := recover() if e != nil { err = panicutil.MakeError(e) logger.WithError(err). WithField("stack", errorutil.Callers(10000)). Error("panic occurred") } if sentryHub != nil { sentryHub.Flush(2 * time.Second) } }() err = do(ctx, cmd, args) if err != nil { logger.WithError(err).Error("command exit") } return err } }
Functions ¶
func NewLoggerFactory ¶
Types ¶
type BinderGetter ¶
type BinderGetter func() *cobraviper.Binder
type InputRunEFunc ¶
Click to show internal directories.
Click to hide internal directories.