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 1 commit
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
7 changes: 7 additions & 0 deletions example/logrus/main.go
Expand Up @@ -43,9 +43,16 @@ func main() {
defer sentryHook.Flush(5 * time.Second)
logger.AddHook(sentryHook)

// 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

// The following line is logged to STDERR, but not to Sentry
Mindstan marked this conversation as resolved.
Show resolved Hide resolved
logger.Infof("Application has started")

// The following line is logged to STDERR and also sent to Sentry
Mindstan marked this conversation as resolved.
Show resolved Hide resolved
logger.Errorf("oh no!")

// The following line is logged to STDERR, sent to Sentry, then the program abruptly stops
Mindstan marked this conversation as resolved.
Show resolved Hide resolved
logger.Fatalf("can't continue...")
}