Skip to content
This repository has been archived by the owner on Apr 23, 2018. It is now read-only.
/ trace Public archive
forked from gravitational/trace

Package for error handling and error reporting

License

Notifications You must be signed in to change notification settings

containous/trace

 
 

Repository files navigation

Trace

GoDoc

Package for error handling and error reporting

Read more here:

http://gravitational.com/blog/golang_error_handling/

Capture file, line and function

import (
     "github.com/gravitational/trace"
)

func someFunc() error {
   return trace.Wrap(err)
}


func main() {
  err := someFunc()
  fmt.Println(err.Error()) // prints file, line and function
}

Emit structured logs to Elastic search using udpbeat

Add trace's document template to your ElasticSearch cluster

curl -XPUT 'http://localhost:9200/_template/trace' -d@udbbeat/template.json

Start udpbeat UDP logs collector and emitter

go get github.com/gravitational/udpbeat
udpbeat

Hook up logger to UDP collector

In your code, attach a logrus hook to use udpbeat:

import (
   "github.com/gravitational/trace"
   log "github.com/sirupsen/logrus"
)

func main() {
   hook, err := trace.NewUDPHook()
   if err != nil {
       log.Fatalf(err)
   }
   log.SetHook(hook)
}

Done! You will get structured logs capturing output, log and error message. You can edit udpbeat/template.json to modify emitted fields to whatever makes sense to your app.

About

Package for error handling and error reporting

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%