Documentation ¶
Index ¶
- Variables
- func As[T error](inner error) T
- func FromErrors(errs ...error) error
- type AggregateError
- type ErrorProvider
- type GError
- type Logger
- func (logger *Logger) ChangeFrame(skipFrames int) *Logger
- func (logger *Logger) Discard()
- func (logger *Logger) Error(inner error, message string, args ...interface{}) *GError
- func (logger *Logger) FrameError(frame int, inner error, message string, args ...interface{}) *GError
- func (logger *Logger) Log(message string, args ...interface{})
- type LoggerOption
- type WithErrorLog
- type WithErrorProvider
- type WithInfoLog
- type WithPrefix
Constants ¶
This section is empty.
Variables ¶
var DefaultErrorProvider = ErrorProvider{SkipFrames: 2, PackageBase: "goutils"}
DefaultErrorProvider contains the default settings to use when generating errors
Functions ¶
Types ¶
type AggregateError ¶
type AggregateError []error
AggregateError is a wrapper for multiple errors
func (AggregateError) Error ¶
func (err AggregateError) Error() string
Error generates an error string from an aggregate error
type ErrorProvider ¶
ErrorProvider is a type that can be used when generating errors to ensure that the error is generated in the proper context
func (ErrorProvider) GenerateError ¶
func (provider ErrorProvider) GenerateError(env string, inner error, message string, args ...interface{}) *GError
GenerateBackendError creates a new error from an environment variable, an inner error, a message and a list of arguments to inject into the message. Note that this function assumes that the caller generated this error. If that is not the case then a custom error provider should be used with the proper number of skip frames. See the runtime documentation for more information.
type GError ¶
type GError struct { Environment string Package string Class string Function string File string LineNumber int GeneratedAt time.Time Message string Inner error }
GError contains information necessary to represent an error. We use the value GError instead of Error so, if it is embedded into another type, it will not invalidate the error interface
type Logger ¶
Logger contains the data necessary to log status and error messages in a standard way
func NewLogger ¶
func NewLogger(service string, environment string, opts ...LoggerOption) *Logger
NewLogger creates a new logger from the service name and environment name
func (*Logger) ChangeFrame ¶
ChangeFrame creates a new logger from an existing logger with a different number of frames to skip, allowing for errors to be referenced from a different part of the call stack than the default logger
func (*Logger) Discard ¶
func (logger *Logger) Discard()
Discard is primarily used for testing. It operates by setting the output from all the loggers to a discard stream so that no logging actually appears on the screen
func (*Logger) Error ¶
Generate and log an error from the inner error and message. The resulting error will be returned for use by the caller
type LoggerOption ¶
type LoggerOption interface {
// contains filtered or unexported methods
}
LoggerOption describes the functions necessary to modify a logger at creation
type WithErrorLog ¶
WithErrorLog allows the user to set the log to which error messages will be sent
type WithErrorProvider ¶
type WithErrorProvider ErrorProvider
WithErrorProvider allows the user to set the error provider which defines the behavior the logger should exhibit when an error message is generated
type WithInfoLog ¶
WithInfoLog allows the user to set the log to which information messages will be sent
type WithPrefix ¶
type WithPrefix string
WithPrefix allows the user to set the prefix prepended to all log messages