Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | 19-Feb-2022 | - | ||||
.gitignore | H A D | 19-Feb-2022 | 266 | 25 | 19 | |
LICENSE | H A D | 19-Feb-2022 | 11 KiB | 201 | 169 | |
README.md | H A D | 19-Feb-2022 | 1.3 KiB | 73 | 45 | |
errors.go | H A D | 19-Feb-2022 | 12.6 KiB | 486 | 328 | |
httplib.go | H A D | 19-Feb-2022 | 3.4 KiB | 134 | 117 | |
log.go | H A D | 19-Feb-2022 | 7.2 KiB | 316 | 231 | |
trace.go | H A D | 19-Feb-2022 | 12.7 KiB | 515 | 399 | |
udphook.go | H A D | 19-Feb-2022 | 2.4 KiB | 113 | 92 |
README.md
1# Trace 2 3[![GoDoc](https://godoc.org/github.com/gravitational/trace?status.png)](https://godoc.org/github.com/gravitational/trace) 4 5 6Package for error handling and error reporting 7 8Read more here: 9 10http://gravitational.com/blog/golang_error_handling/ 11 12### Capture file, line and function 13 14```golang 15 16import ( 17 "github.com/gravitational/trace" 18) 19 20func someFunc() error { 21 return trace.Wrap(err) 22} 23 24 25func main() { 26 err := someFunc() 27 fmt.Println(err.Error()) // prints file, line and function 28} 29``` 30 31### Emit structured logs to Elastic search using udpbeat 32 33**Add trace's document template to your ElasticSearch cluster** 34 35```shell 36curl -XPUT 'http://localhost:9200/_template/trace' -d@udbbeat/template.json 37``` 38 39**Start udpbeat UDP logs collector and emitter** 40 41```shell 42go get github.com/gravitational/udpbeat 43udpbeat 44``` 45 46**Hook up logger to UDP collector** 47 48In your code, attach a logrus hook to use udpbeat: 49 50```golang 51 52import ( 53 "github.com/gravitational/trace" 54 log "github.com/sirupsen/logrus" 55) 56 57func main() { 58 hook, err := trace.NewUDPHook() 59 if err != nil { 60 log.Fatalf(err) 61 } 62 log.SetHook(hook) 63} 64``` 65 66Done! You will get structured logs capturing output, log and error message. 67You can edit `udpbeat/template.json` to modify emitted fields to whatever makes sense to your app. 68 69 70 71 72 73