panicwatch

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2020 License: MIT Imports: 9 Imported by: 5

README

panicwatch

CI

Simple utility for catching panics in your Go applications.

When you start panicwatch, it creates a new process which watches your application. When the application exits, panicwatch parses the stderr output of your application and if it finds a panic, it will report it using configured callback. Panicwatch doesn't block usage of stderr of your application in any way as it uses dup to get a copy of it.

Panicwatch isn't meant for recovery from panics, but merely for safe and reliable logging when they happen.

err := panicwatch.Start(panicwatch.Config{
    OnPanic: func(p panicwatch.Panic) {
        sentry.Log("panic: "+p.Message, "stack", p.Stack)
    },
    OnWatcherDied: func(err error) {
        app.ShutdownGracefully()
    }, 
})
if err != nil {
    log.Fatal("failed to start panicwatch: " + err.error)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Start

func Start(config Config) error

Types

type Config

type Config struct {
	OnPanic        func(Panic) // required
	OnWatcherError func(error) // optional, used for reporting watcher process errors
	OnWatcherDied  func(error) // optional, you should provide it to shutdown your application gracefully
}

type Panic

type Panic struct {
	Message string
	Stack   string
}

Directories

Path Synopsis
cmd
test command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL