Documentation ¶
Index ¶
- func GetEchoLoggerMiddleware(logger ErrorLogger) echo.MiddlewareFunc
- func New(message string) *richError
- type BasicLogger
- type ChainLogger
- type CodeInfodeprecated
- type ContextLogger
- type ErrorLogger
- type FormattedLogger
- type GRPCInterceptors
- type GoLogger
- type Kind
- type Level
- type Logger
- type Metadata
- type Operation
- type RichError
- type RuntimeInfo
- type SentryLogger
- type StringType
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetEchoLoggerMiddleware ¶
func GetEchoLoggerMiddleware(logger ErrorLogger) echo.MiddlewareFunc
Types ¶
type BasicLogger ¶
type BasicLogger interface { Debug(...interface{}) Info(...interface{}) Warn(...interface{}) Error(...interface{}) Panic(...interface{}) Fatal(...interface{}) }
type ChainLogger ¶
type ChainLogger struct {
Loggers []ErrorLogger
}
ChainLogger is an ErrorLogger that upon being called will call a set of loggers one after the other
func (ChainLogger) Log ¶
func (c ChainLogger) Log(err error)
func (ChainLogger) LogInfo ¶
func (c ChainLogger) LogInfo(msg string)
func (ChainLogger) LogInfoWithMetadata ¶
func (c ChainLogger) LogInfoWithMetadata(msg string, metadata ...interface{})
type CodeInfo
deprecated
type CodeInfo RuntimeInfo
Deprecated: CodeInfo has been renamed to RuntimeInfo and will be removed in V2
type ContextLogger ¶
type ErrorLogger ¶
type ErrorLogger interface { Log(error) LogInfo(string) LogInfoWithMetadata(string, ...interface{}) }
func ChainLoggers ¶
func ChainLoggers(loggers ...ErrorLogger) ErrorLogger
type FormattedLogger ¶
type GRPCInterceptors ¶
type GRPCInterceptors struct {
Logger ErrorLogger
}
GRPCInterceptors is a helper that provides unary and stream grpc interceptors that will catch and log errors of your grpc server. If your grpc services return RichError it will set the grpc status code based on their Kind. Keep in mind that these interceptors will not log errors regarding the reflection API.
func (GRPCInterceptors) StreamInterceptor ¶
func (h GRPCInterceptors) StreamInterceptor() grpc.StreamServerInterceptor
StreamInterceptor returns a gRPC stream interceptor that intercepts every gRPC request and in case of error prints (or logs) error and sets the grpc status code according to the error Kind. It also recovers panics.
func (GRPCInterceptors) UnaryInterceptor ¶
func (h GRPCInterceptors) UnaryInterceptor() grpc.UnaryServerInterceptor
UnaryInterceptor returns a gRPC unary interceptor that intercepts every gRPC request and in case of error prints (or logs) error and sets the grpc status code according to the error Kind. It also recovers panics.
type Kind ¶
type Kind kind
Kind hints about underlying cause of error
const ( UnknownKind Kind = iota Canceled // grpc: CANCELLED - http 500 Internal Server Error Unknown // grpc: UNKNOWN - http 500 Internal Server Error InvalidArgument // grpc: INVALID_ARGUMENT - http 400 Bad Request Timeout // grpc: DEADLINE_EXCEEDED - http 500 Internal Server Error NotFound // grpc: NOT_FOUND - http 404 Not Found AlreadyExists // grpc: ALREADY_EXISTS - http 409 Conflict PermissionDenied // grpc: PERMISSION_DENIED - http 403 Forbidden TooManyRequests // grpc: RESOURCE_EXHAUSTED - http 429 Too Many Requests Unimplemented // grpc: UNIMPLEMENTED - http 501 Not Implemented Internal // grpc: INTERNAL - http 500 Internal Server Error Unauthenticated // grpc: UNAUTHENTICATED - http 401 Unauthorized Invalid = InvalidArgument Unexpected = Unknown )
func (Kind) GRPCStatusCode ¶
func (Kind) HttpStatusCode ¶
func (Kind) MarshalJSON ¶
type Level ¶
type Level level
Level identifies severity of the error
func (Level) MarshalJSON ¶
func (Level) SentryLevel ¶
func (l Level) SentryLevel() sentry.Level
type Logger ¶
type Logger struct { GoLogger GoLogger BasicLogger BasicLogger FormattedLogger FormattedLogger ContextLogger ContextLogger }
Logger is a struct that provides an ErrorLogger. The resulting ErrorLogger will log RichErrors given to it as descriptive as it can (based on the loggers abilities). Keep in mind that it's the module users' responsibility to give the struct their desired loggers. It will try to use ContextLogger which logs the error along with all of its Metadata. If not exists it will try FormattedLogger, BasicLogger, and GoLogger in that order. Finally, if no logger has been defined it will use fmt.Println to log the error.
func (Logger) LogInfoWithMetadata ¶
type RichError ¶
type RichError interface { String() string Error() string Unwrap() error Is(target error) bool As(target interface{}) bool Metadata() Metadata RuntimeInfo() []RuntimeInfo Operation() Operation Level() Level Type() Type Kind() Kind // Deprecated: CodeInfo has been renamed to RuntimeInfo and will be removed in V2 CodeInfo() CodeInfo }
RichError is a richer type of error that holds runtime information with itself
type RuntimeInfo ¶
type RuntimeInfo struct { LineNumber int `json:"line_number,omitempty"` FileName string `json:"file_name,omitempty"` FunctionName string `json:"function_name,omitempty"` }
RuntimeInfo stores runtime information about the code
func (*RuntimeInfo) String ¶
func (s *RuntimeInfo) String() string
type SentryLogger ¶
SentryLogger is a ErrorLogger that logs to sentry. The returned ErrorLogger will report details of your errors (if they're RichError) to the sentry using `sentry-go` module.
func (SentryLogger) Log ¶
func (s SentryLogger) Log(err error)
func (SentryLogger) LogInfo ¶
func (s SentryLogger) LogInfo(string)
func (SentryLogger) LogInfoWithMetadata ¶
func (s SentryLogger) LogInfoWithMetadata(string, ...interface{})
type StringType ¶
type StringType string
func (StringType) String ¶
func (et StringType) String() string