• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..19-Feb-2022-

.gitignoreH A D19-Feb-2022266 2519

LICENSEH A D19-Feb-202211 KiB201169

README.mdH A D19-Feb-20221.3 KiB7345

errors.goH A D19-Feb-202212.6 KiB486328

httplib.goH A D19-Feb-20223.4 KiB134117

log.goH A D19-Feb-20227.2 KiB316231

trace.goH A D19-Feb-202212.7 KiB515399

udphook.goH A D19-Feb-20222.4 KiB11392

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