zaperr

package module
v0.0.0-...-bfd0551 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2021 License: MIT Imports: 4 Imported by: 16

README

zaperr

CircleCI Coverage Status GoDoc

Error wrapper for go.uber.org/zap

Usage

err = zaperr.Wrap(err, "failed to execute something",
    zap.Int("foo", 1),
    zap.String("bar", "baz"),
)

logger.Info("example", zaperr.ToField(err))

// Output:
// {"level":"info","msg":"example","error":{"foo":1,"bar":"baz","error":"failed to execute something: error","errorVerbose":"omitted..."}}

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

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Errorf

func Errorf(format string, args ...interface{}) error

func New

func New(message string, fields ...zap.Field) error

func ToField

func ToField(err error) zap.Field

func ToNamedField

func ToNamedField(key string, err error) zap.Field

func WithFields

func WithFields(err error, fields ...zap.Field) error

func Wrap

func Wrap(err error, message string, fields ...zap.Field) error

Types

type Wrapper

type Wrapper struct {
	// contains filtered or unexported fields
}

func WrapperWith

func WrapperWith(fields ...zap.Field) Wrapper

func (Wrapper) Errorf

func (w Wrapper) Errorf(format string, args ...interface{}) error

func (Wrapper) New

func (w Wrapper) New(message string, fields ...zap.Field) error

func (Wrapper) WithFields

func (w Wrapper) WithFields(err error, fields ...zap.Field) error

func (Wrapper) Wrap

func (w Wrapper) Wrap(err error, message string, fields ...zap.Field) error

func (Wrapper) WrapperWith

func (w Wrapper) WrapperWith(fields ...zap.Field) Wrapper

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL