From 90e63f2f1ea978504af083f766ab9afa7afa41e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Blond?= Date: Wed, 7 Dec 2022 15:19:58 +0100 Subject: [PATCH] Add docs on how to handle logrus.Fatalf events (#501) Co-authored-by: Michi Hoffmann --- example/logrus/main.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/example/logrus/main.go b/example/logrus/main.go index a2870d7e4..d28b93a29 100644 --- a/example/logrus/main.go +++ b/example/logrus/main.go @@ -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...") }