Skip to content

Commit

Permalink
Add docs on how to handle logrus.Fatalf events (#501)
Browse files Browse the repository at this point in the history
Co-authored-by: Michi Hoffmann <cleptric@users.noreply.github.com>
  • Loading branch information
Mindstan and cleptric authored Dec 7, 2022
1 parent f2026b4 commit 90e63f2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions example/logrus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,16 @@ func main() {
defer sentryHook.Flush(5 * time.Second)
logger.AddHook(sentryHook)

// The following line is logged to STDERR, but not to Sentry
// Flushes before calling os.Exit(1) when using logger.Fatal
// (else all defers are not called, and Sentry does not have time to send the event)
logrus.RegisterExitHandler(func() { sentryHook.Flush(5 * time.Second) })

// Log a InfoLevel entry STDERR which is not send to Sentry
logger.Infof("Application has started")

// The following line is logged to STDERR and also sent to Sentry
// Log an error to STDERR which is also send to Sentry
logger.Errorf("oh no!")

// Log a fatal error to STDERR, which sends an event to Sentry and terminates the application
logger.Fatalf("can't continue...")
}

0 comments on commit 90e63f2

Please # to comment.