Documentation
¶
Overview ¶
Packgae idea is to separate static errors, that are used to determine behavior if error happened.
From context-of-error, like dynamic data, trace and/or messages, that, on the other hand, used for logging and debugging.
This is zerolog specific package, so it is not suitable to use with any other logger, or for different purpose.
Compatable with errors package.
Any mention of a "context" in this package means messages or values, that stored inside ZeroError, and not context.Context.
Index ¶
Constants ¶
const ( // Default key for first message. FirstKey = "root" // Defaylt key for string message. MessageKey = "msg" // Default key for value message. ValueKey = "data" // Default key for error. ErrorKey = "error" // Default key when dictionary logged out. InsertedKey = "errcontext" )
Variables ¶
This section is empty.
Functions ¶
func TryInsert ¶
TryInsert retuned func will add static error, followed by context to zerolog.Event. ¶
Usage: logger.Debug().Func(TryInsert(err)).Send() .
It is guaranteed that key will be InsertedKey key.
If error is not an ZeroError -- returned function is a no-op.
Types ¶
type ZeroError ¶
type ZeroError struct {
// contains filtered or unexported fields
}
ZeroError is a container for separately stored static error and logging context.
Any mention of a "context" in this package means messages or values, that stored inside ZeroError, and not context.Context.
func New ¶
func New() *ZeroError
New returns ready to use ZeroError.
Fields:
- err filed initialized with 0 len string error, not nil.
- event field initialized with ready-to-use zerolog.Dict(), not nil.
It is better for maintenance and readability to use [With*] functions ! ¶
func WithKeyMsg ¶
WithKeyMsg adds key-msg pair to newly initialized ZeroError. ¶
If called on already initialized ZeroError then WithKeyMsg just add more info.
It is guaranteed:
- even if this is the rirst message of the event, key will be used, insted of FirstKey key.
func WithKeyVal ¶
WithKeyVal adds key-value pair to newly initialized ZeroError. ¶
If called on already initialized ZeroError then WithKeyVal just add more info.
It is guaranteed:
- even if this is the rirst message of the event, key will be used, insted of FirstKey key.
func WithMsg ¶
WithMsg adds msg to newly initialized ZeroError. ¶
If called on already initialized ZeroError then WithMsg just add more info.
It is guaranteed:
- if message is first in event -- it will be with FirstKey key.
- added msg will be with MessageKey key.
func WithVal ¶
WithVal adds value to newly initialized ZeroError. ¶
Be careful, only exported fields of a struct will be added !!! ¶
If called on already initialized ZeroError then WithVal just add more info.
It is guaranteed: