recovery

package
v0.0.0-...-0df0820 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package recovery provides a number of grip-integrated panic handling tools for capturing and responding to panics using grip loggers.

These handlers are very useful for capturing panic messages that might otherwise be lost, as well as providing implementations for several established panic handling practices. Nevertheless, this assumes that the panic, or an underlying system issue does not affect the logging system or its dependencies. For example, panics caused by disk-full or out of memory situations are challenging to handle with this approach.

All log message are logged with the default standard logger in the grip package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandlePanicWithError

func HandlePanicWithError(p interface{}, err error, opDetails ...string) error

HandlePanicWithError is used to convert a panic to an error.

The "opDetails" argument is optional, and is joined as an "operation" field in the log message for providing additional context.

You must construct a recovery function as in the following example:

defer func() { err = recovery.HandlePanicWithError(recover(),  err, "op") }()

This defer statement must occur in a function that declares a default error return value as in:

func operation() (err error) {}

func LogStackTraceAndContinue

func LogStackTraceAndContinue(opDetails ...string)

LogStackTraceAndContinue recovers from a panic, and then logs the captures a stack trace and logs a structured message at "Alert" level without further action.

The "opDetails" argument is optional, and is joined as an "operation" field in the log message for providing additional context.

Use in a common defer statement, such as:

defer recovery.LogStackTraceAndContinue("operation")

func LogStackTraceAndExit

func LogStackTraceAndExit(opDetails ...string)

LogStackTraceAndExit captures a panic, captures and logs a stack trace at the Emergency level and then exits.

This operation also attempts to close the underlying log sender.

Types

This section is empty.

Jump to

Keyboard shortcuts

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