-
Notifications
You must be signed in to change notification settings - Fork 1
/
writer.go
61 lines (48 loc) · 928 Bytes
/
writer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package report
import (
"encoding/json"
"io"
"os"
"github.com/honeycombio/libhoney-go"
)
// Exporter exports events to an external service
type Exporter interface {
Send(d Data) error
Close()
}
// JSON writes JSON formatted logs
func JSON(w io.Writer) Exporter {
return jw{
encoder: json.NewEncoder(w),
}
}
// StdOutJSON writes logs to StdOut as JSON
func StdOutJSON() Exporter {
return JSON(os.Stdout)
}
// Honeycomb sends log events to HoneyComb
func Honeycomb(key string, dataset string) Exporter {
libhoney.Init(libhoney.Config{
WriteKey: key,
Dataset: dataset,
})
return hw{}
}
// json writer
type jw struct {
encoder *json.Encoder
}
func (w jw) Send(d Data) error {
return w.encoder.Encode(d)
}
func (w jw) Close() {}
// honeycomb writer
type hw struct{}
func (w hw) Send(d Data) error {
ev := libhoney.NewEvent()
ev.Add(d)
return ev.Send()
}
func (w hw) Close() {
libhoney.Close()
}