Documentation
¶
Index ¶
- Variables
- func CloseWithErrCapture(c io.Closer, capture *error, opts ...Option)
- func CloseWithErrChan(c io.Closer, errChan chan<- error, opts ...Option)
- func CloseWithLogOnErr(c io.Closer, opts ...Option)
- func RecoverWithErrCapture(capture *error, opts ...Option)
- func RecoverWithErrChan(errChan chan<- error, opts ...Option)
- func SetGlobalOptions(opts ...Option)
- func SetPackageLevelOptions(opts ...Option)
- func Stacktrace(err error, _ ...Option) (traceEntries []string)
- func StopWithErrCapture(c Stopper, capture *error, opts ...Option)
- func StopWithErrChan(c Stopper, errChan chan<- error, opts ...Option)
- func StopWithErrLog(c Stopper, opts ...Option)
- type LogrusLikeLoggingFunc
- type Option
- func IncludeNonProjectFiles() Option
- func IncludedPackages(pkgs ...string) Option
- func LogWithLogrus(lf LogrusLikeLoggingFunc) Option
- func LogWithPrintfFamily(lf PrintfFamily) Option
- func WithDetailedTrace() Option
- func WithLogHandler(handler func(err string)) Option
- func WrapWithFmtErrorf() Option
- func Wrapf(format string, args ...interface{}) Option
- type Options
- type PanicError
- type PrintfFamily
- type Stopper
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func CloseWithErrCapture ¶
CloseWithErrCapture is used if you want to close and fail the function or method on a `io.Closer.Close()` error (make sure the `error` return argument is named as `err`). If the error is already present, `CloseWithErrCapture` will append the error caused by `Close` if any.
func CloseWithErrChan ¶
CloseWithErrChan is used if you want to close and fail the function or method on a `io.Closer.Close()` error (make sure the `error` return argument is named as `err`). If the error is already present, `CloseWithErrChan` will send the error to the given channel caused by `Close` if any.
func CloseWithLogOnErr ¶ added in v0.1.1
CloseWithLogOnErr is used if you want to close and fail the function or method on a `io.Closer.Close()` error (make sure the `error` return argument is named as `err`). If the error is already present, `CloseWithLogOnErr` will log the error caused by `Close` if any.
func RecoverWithErrCapture ¶
func RecoverWithErrChan ¶
func SetGlobalOptions ¶
func SetGlobalOptions(opts ...Option)
SetGlobalOptions sets options applied in current package scope. It can override global options.
func SetPackageLevelOptions ¶
func SetPackageLevelOptions(opts ...Option)
SetPackageLevelOptions sets options applied in current package scope. It can override global options.
func Stacktrace ¶
Stacktrace returns pretty-formatted stack trace of an error created or wrapped by `github.com/pkg/errors` package. Runtime stack traces are skipped for simplicity.
func StopWithErrCapture ¶
StopWithErrCapture is used if you want to Stop and fail the function or method on a `Stop()` error (make sure the `error` return argument is named as `err`). If the error is already present, `StopWithErrCapture` will append the error caused by `Stop` if any.
func StopWithErrChan ¶
StopWithErrChan is used if you want to Stop and fail the function or method on a `Stop()` error (make sure the `error` return argument is named as `err`). If the error is already present, `StopWithErrChan` will send the error to the given channel caused by `Stop` if any.
func StopWithErrLog ¶
StopWithErrLog is used if you want to Stop and fail the function or method on a `Stop()` error (make sure the `error` return argument is named as `err`). If the error is already present, `StopWithErrLog` will log the error caused by `Stop` if any.
Types ¶
type LogrusLikeLoggingFunc ¶
type LogrusLikeLoggingFunc func(...interface{})
LogrusLikeLoggingFunc includes leveled logging functions on Logrus. https://github.com/sirupsen/logrus#level-logging Other loggers sharing same function signature can be also used.
type Option ¶
type Option func(o *Options)
func IncludeNonProjectFiles ¶
func IncludeNonProjectFiles() Option
IncludeNonProjectFiles is an option for including non-project files to stacktrace. It is not recommended to use this option for production because it refers GOPATH from environment variable for the decision. IncludedPackages is recommended.
func IncludedPackages ¶
IncludedPackages is an option specifying allowed list of package names in stacktrace. If set, only packages starting with given names will be included.
func LogWithLogrus ¶
func LogWithLogrus(lf LogrusLikeLoggingFunc) Option
LogWithLogrus is an option for using logrus on functions end with "WithErrorLog".
func LogWithPrintfFamily ¶
func LogWithPrintfFamily(lf PrintfFamily) Option
LogWithPrintfFamily is an option for using printf-like loggers on functions end with "WithErrorLog".
func WithDetailedTrace ¶
func WithDetailedTrace() Option
WithDetailedTrace is an option for dumping running goroutine and its traces will be dumped.
func WithLogHandler ¶
WithLogHandler is an option for specifying custom logger on functions end with "WithErrorLog".
func WrapWithFmtErrorf ¶
func WrapWithFmtErrorf() Option
WrapWithFmtErrorf is an option for using fmt.Errorf on error wrapping.
type Options ¶
type Options struct { // Logger specifies logging function used on functions end with "WithErrLog". // It uses `log.Println` by default. Logger func(err string) // DetailedStacktrace specifies verbosity of stacktrace. // If it's true, running goroutine and its traces will be dumped. // Otherwise, it only dumps package and function name with source lines, similar to Java's. DetailedStacktrace bool // SkipNonProjectFiles specifies whether to skip stacktrace from non-project sources. // true by default. // // It is not recommended to use this option for production because it refers // GOPATH from environment variable for the decision. IncludedPackages is recommended. SkipNonProjectFiles bool // IncludedPackages specifies allowed list of package names in stacktrace. // If set, only packages starting with given names will be included. IncludedPackages []string // WrapArguments specifies additional context info added on error. // If first argument is string, it is used to format message with rest of the arguments and // will be passed to errors.Wrapf (by default) or fmt.Errorf (optional). WrapArguments []interface{} // WrapWithFmtErrorf specifies whether to use fmt.Errorf on error wrapping. false by default. WrapWithFmtErrorf bool }
type PanicError ¶
func WrapPanic ¶
func WrapPanic(recovered interface{}, opt ...Option) *PanicError
func (PanicError) Error ¶
func (pe PanicError) Error() string
func (PanicError) Pretty ¶
func (pe PanicError) Pretty() (desc string)
type PrintfFamily ¶
type PrintfFamily func(string, ...interface{})