-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathraygun.go
50 lines (40 loc) · 1012 Bytes
/
raygun.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
package raygun
import (
"errors"
"net/http"
"github.com/Sirupsen/logrus"
"github.com/sditools/goraygun"
)
type raygunHook struct {
Client *goraygun.Client
}
func NewHook(endpoint string, apiKey string, env string) *raygunHook {
client := goraygun.Init(goraygun.Settings{
ApiKey: apiKey,
Endpoint: endpoint,
Environment: env,
}, goraygun.Entry{})
return &raygunHook{client}
}
func (hook *raygunHook) Fire(logEntry *logrus.Entry) error {
// Start with a copy of the default entry
raygunEntry := hook.Client.Entry
if request, ok := logEntry.Data["request"]; ok {
raygunEntry.Details.Request.Populate(*(request.(*http.Request)))
}
var reportErr error
if err, ok := logEntry.Data["error"]; ok {
reportErr = err.(error)
} else {
reportErr = errors.New(logEntry.Message)
}
hook.Client.Report(reportErr, raygunEntry)
return nil
}
func (hook *raygunHook) Levels() []logrus.Level {
return []logrus.Level{
logrus.ErrorLevel,
logrus.FatalLevel,
logrus.PanicLevel,
}
}