evalphobia / logrus_sentry

sentry hook for logrus
MIT License
194 stars 78 forks source link

Add error handler for Sentry error #78

Closed evalphobia closed 5 years ago

evalphobia commented 5 years ago

This PR adds error handler used when Sentry omits error.

Example usage is like below,

var sentryErrCounter uint64 = 0

func initLogrusHook() {
    hook, _ := logrus_sentry.NewSentryHook(dsn, []logrus.Level{
        logrus.ErrorLevel,
    })

    // increment Sentry error counter
    incrementErrCounterHandle := func(entry *logrus.Entry, err error) {
        atomic.AddUint64(&sentryErrCounter, 1)
        fmt.Printf("[Sentry Error] %s\n", err.Error())
    }

    hook.AddErrorHandler(incrementErrCounterHandle)

    // ...