recovery

package
v0.0.0-...-863240d Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2022 License: Apache-2.0 Imports: 8 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 AnnotateMessageWithPanicError

func AnnotateMessageWithPanicError(p interface{}, err error, m interface{}) error

AnnotateMessageWithPanicError processes a panic and converts it into an error, combining it with the value of another error. Like, HandlePanicWithError, this method is meant to be used in your own defer functions.

It takes an interface which it converts to a message.Composer using the same rules as logging methods, and annotates those messages with the stack trace and panic information.

func AnnotateMessageWithStackTraceAndContinue

func AnnotateMessageWithStackTraceAndContinue(m interface{})

AnnotateMessageWithStackTraceAndContinue logs panics and continues and is meant to be used in defer statements like LogStackTraceAndContinue.

It takes an interface which it converts to a message.Composer using the same rules as logging methods, and annotates those messages with the stack trace and panic information.

func AnnotateMessageWithStackTraceAndExit

func AnnotateMessageWithStackTraceAndExit(m interface{})

AnnotateMessageWithStackTraceAndExit logs panics and calls exit like LogStackTraceAndExit.

It takes an interface which it converts to a message.Composer using the same rules as logging methods, and annotates those messages with the stack trace and panic information.

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.

func SendMessageWithPanicError

func SendMessageWithPanicError(p interface{}, err error, logger grip.Journaler, m interface{}) error

SendMessageWithPanicError is similar to AnnotateMessageWithPanicError, but allows you to inject a custom grip.Jounaler interface to receive the log message.

func SendStackTraceAndContinue

func SendStackTraceAndContinue(logger grip.Journaler, m interface{})

SendStackTraceAndContinue is similar to AnnotateMessageWithStackTraceAndContinue, but allows you to inject a grip.Journaler interface to receive the log message.

func SendStackTraceMessageAndExit

func SendStackTraceMessageAndExit(logger grip.Journaler, m interface{})

SendStackTraceMessageAndExit is similar to AnnotateMessageWithStackTraceAndExit, but allows you to inject a grip.Journaler interface.

Types

This section is empty.

Jump to

Keyboard shortcuts

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