Documentation
¶
Overview ¶
Example ¶
package main
import (
"os"
"github.com/JohannWeging/logerr"
"github.com/juju/errors"
log "github.com/sirupsen/logrus"
)
func main() {
// make logrus play nice with go test
log.SetOutput(os.Stdout)
log.SetFormatter(&log.TextFormatter{DisableTimestamp: true})
err := job()
if err != nil {
fields := logerr.GetFields(err)
log.WithFields(fields).Errorf("job failed: %s", err)
}
}
func job() error {
err := task()
if err != nil {
err = logerr.WithField(err, "jobID", "0")
err = errors.Annotate(err, "task failed")
return err
}
return nil
}
func task() error {
return errors.New("cause")
}
Output: level=error msg="job failed: task failed: cause" jobID=0
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeferWithFields ¶
func WithFields ¶
WithFields adds a new field map to the error
Types ¶
type Error ¶
type Error struct {
Fields map[string]interface{}
// contains filtered or unexported fields
}
Error holds the added fields
func (*Error) Underlying ¶
Underlying implements the juju/errors wrapper interface
Click to show internal directories.
Click to hide internal directories.