onrik / logrus

Hooks for logrus logging
MIT License
122 stars 30 forks source link

Fix example: logrus.AddHook() args + add deferred flush #22

Closed angristan closed 3 years ago

angristan commented 3 years ago

The levels have to be set earlier, otherwise the example can't run:

» go run main.go
# command-line-arguments
./main.go:27:13: too many arguments in call to logrus.AddHook
    have (*"github.com/onrik/logrus/sentry".Hook, logrus.Level, logrus.Level, logrus.Level)
    want (logrus.Hook)

Also, sentry-go flushes event asynchronously, so if we don't wait after the final log.Error(), the program will be terminated before the event is sent. I added a defer sentryHook.Flush() otherwise the example doesn't work.