-
Notifications
You must be signed in to change notification settings - Fork 2
/
loggly_hook.go
59 lines (48 loc) · 1.04 KB
/
loggly_hook.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
package log
import (
"os"
"time"
"github.com/segmentio/go-loggly"
"github.com/sirupsen/logrus"
)
// NewLogglyHook creates a new hook
func NewLogglyHook(token string) *LogglyHook {
client := loggly.New(token, "frontier")
host, err := os.Hostname()
if err != nil {
panic("couldn't get hostname")
}
return &LogglyHook{
client: client,
host: host,
}
}
func (hook *LogglyHook) Fire(entry *logrus.Entry) error {
logglyMessage := loggly.Message{
"timestamp": entry.Time.UTC().Format(time.RFC3339Nano),
"level": entry.Level.String(),
"message": entry.Message,
"hostname": hook.host,
}
for k, v := range entry.Data {
//Filter out keys
if _, ok := hook.FilteredKeys[k]; ok {
continue
}
logglyMessage[k] = v
}
return hook.client.Send(logglyMessage)
}
func (hook *LogglyHook) Flush() {
hook.client.Flush()
}
func (hook *LogglyHook) Levels() []logrus.Level {
return []logrus.Level{
logrus.PanicLevel,
logrus.FatalLevel,
logrus.ErrorLevel,
logrus.WarnLevel,
logrus.InfoLevel,
logrus.DebugLevel,
}
}