Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added doc on how to handle logrus.Fatalf events #501

Merged
merged 6 commits into from Dec 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions example/logrus/main.go
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)
cleptric marked this conversation as resolved.
Show resolved Hide resolved
logrus.RegisterExitHandler(func() { sentryHook.Flush(5 * time.Second) })
cleptric marked this conversation as resolved.
Show resolved Hide resolved

// 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...")
}