paniclog

package module
v0.0.0-...-43a7fa3 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2019 License: MIT Imports: 3 Imported by: 4

README

go-paniclog

By default, panics in golang are sent to stderr. Unfortunately, there isn't a direct builtin global mechanism to capture/send the output of the panic to a file or really do anything with it other than to write to stderr.

One possible solution is that you can redirect stderr to a file, and that's all that this package does. Of course, once you redirect stderr to file, anything else you write to stderr will also end up in that file. v2.0 now includes a function you can use to undo the redirection if you wanted to do that for some reason.

Reference: https://stackoverflow.com/questions/34772012/capturing-panic-in-golang

Alternatives

  • panicwrap may be a better solution for many programs

Author

I can't claim any credit for this idea or the code, it is entirely taken from the rclone program by Nick Craig-Wood.

License

MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type UndoFunction

type UndoFunction func() error

UndoFunction will reverse the redirection

func RedirectStderr

func RedirectStderr(f *os.File) (UndoFunction, error)

RedirectStderr to the file passed in, so that the output of any panics that occur will be sent to that file. The caller may close the file after this function returns.

Of course, anything else written to stderr will also be sent to that file, so don't do that unless that's your intent.

Returns a function that can be used to revert stderr back to the console, or an error if stderr could not be redirected

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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