Documentation ¶
Overview ¶
Example ¶
package main import ( "errors" "regexp" "github.com/hori-ryota/go-testutil/testutil" "github.com/hori-ryota/zaperr" "go.uber.org/zap" ) func main() { testutil.OverwritingExampleOutputWrapper(func() { logger := zap.NewExample() defer logger.Sync() err := errors.New("error") err = zaperr.Wrap(err, "failed to execute something", zap.Int("foo", 1), zap.String("bar", "baz"), ) logger.Info("example", zaperr.ToField(err)) }, func(s []byte) []byte { // replace stdout for excepting the absolute path depending on execution // environment return regexp.MustCompile(`"errorVerbose":"[^"]*"`).ReplaceAll(s, []byte(`"errorVerbose":"omitted..."`)) }) }
Output: {"level":"info","msg":"example","error":{"foo":1,"bar":"baz","error":"failed to execute something: error","errorVerbose":"omitted..."}}
Index ¶
- func Errorf(format string, args ...interface{}) error
- func New(message string, fields ...zap.Field) error
- func ToField(err error) zap.Field
- func ToNamedField(key string, err error) zap.Field
- func WithFields(err error, fields ...zap.Field) error
- func Wrap(err error, message string, fields ...zap.Field) error
- type Wrapper
- func (w Wrapper) Errorf(format string, args ...interface{}) error
- func (w Wrapper) New(message string, fields ...zap.Field) error
- func (w Wrapper) WithFields(err error, fields ...zap.Field) error
- func (w Wrapper) Wrap(err error, message string, fields ...zap.Field) error
- func (w Wrapper) WrapperWith(fields ...zap.Field) Wrapper
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
Click to show internal directories.
Click to hide internal directories.