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 ¶
- func AnnotateMessageWithPanicError(p any, err error, m any) error
- func AnnotateMessageWithStackTraceAndContinue(m any)
- func AnnotateMessageWithStackTraceAndExit(m any)
- func HandlePanicWithError(p any, err error, opDetails ...string) error
- func LogStackTraceAndContinue(opDetails ...string)
- func LogStackTraceAndExit(opDetails ...string)
- func SendMessageWithPanicError(p any, err error, logger grip.Logger, m any) error
- func SendStackTraceAndContinue(logger grip.Logger, m any)
- func SendStackTraceMessageAndExit(logger grip.Logger, m any)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnnotateMessageWithPanicError ¶
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 any)
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 any)
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 ¶
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 ¶
SendMessageWithPanicError is similar to AnnotateMessageWithPanicError, but allows you to inject a custom grip.Jounaler interface to receive the log message.
func SendStackTraceAndContinue ¶
SendStackTraceAndContinue is similar to AnnotateMessageWithStackTraceAndContinue, but allows you to inject a grip.Journaler interface to receive the log message.
func SendStackTraceMessageAndExit ¶
SendStackTraceMessageAndExit is similar to AnnotateMessageWithStackTraceAndExit, but allows you to inject a grip.Journaler interface.
Types ¶
This section is empty.