-
Notifications
You must be signed in to change notification settings - Fork 0
/
logbeat.go
44 lines (38 loc) · 1.11 KB
/
logbeat.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
package logbeat
import (
"github.com/sirupsen/logrus"
)
// LogbeatVersion is used to identify notifications sent by Logbeat.
const LogbeatVersion string = "0.0.3"
// LogbeatHook delivers logs to the Opbeat service.
type LogbeatHook struct {
AppId string
Opbeat *OpbeatClient
OrgId string
SecretToken string
}
// NewOpbeatHook creates a new LogbeatHook that reports
// Errors, Fatal Errors, and Panics from Logrus to Opbeat.
func NewOpbeatHook(org, app, token string) *LogbeatHook {
return &LogbeatHook{
OrgId: org,
AppId: app,
SecretToken: token,
Opbeat: NewOpbeatClient(org, app, token),
}
}
// Fire is called by Logrus when an Error occurs. The given Logrus Entry
// will be sent to Opbeat's Error Intake API.
func (hook *LogbeatHook) Fire(entry *logrus.Entry) error {
_, err := hook.Opbeat.Notify(entry)
return err
}
// Levels tells Logrus which types of logging events we
// are interseted in (e.g. Errors, Fatal Errors, Panics).
func (hook *LogbeatHook) Levels() []logrus.Level {
return []logrus.Level{
logrus.PanicLevel,
logrus.FatalLevel,
logrus.ErrorLevel,
}
}