diff options
author | Wim <wim@42.be> | 2017-03-25 20:45:10 +0100 |
---|---|---|
committer | Wim <wim@42.be> | 2017-03-25 20:45:10 +0100 |
commit | 07fd825349e8b7e86f8afb3843cb8e2c2afc7c74 (patch) | |
tree | ea4b33872a5b925fa0ecd2b421f8f073ba22b2cc /vendor/gopkg.in/gemnasium/logrus-airbrake-hook.v2/airbrake.go | |
parent | be15cc8a36ed3c207251f9b92815781f2fa8618d (diff) | |
download | matterbridge-msglm-07fd825349e8b7e86f8afb3843cb8e2c2afc7c74.tar.gz matterbridge-msglm-07fd825349e8b7e86f8afb3843cb8e2c2afc7c74.tar.bz2 matterbridge-msglm-07fd825349e8b7e86f8afb3843cb8e2c2afc7c74.zip |
Update vendor
Diffstat (limited to 'vendor/gopkg.in/gemnasium/logrus-airbrake-hook.v2/airbrake.go')
-rw-r--r-- | vendor/gopkg.in/gemnasium/logrus-airbrake-hook.v2/airbrake.go | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/vendor/gopkg.in/gemnasium/logrus-airbrake-hook.v2/airbrake.go b/vendor/gopkg.in/gemnasium/logrus-airbrake-hook.v2/airbrake.go new file mode 100644 index 00000000..a92e01ed --- /dev/null +++ b/vendor/gopkg.in/gemnasium/logrus-airbrake-hook.v2/airbrake.go @@ -0,0 +1,71 @@ +package airbrake // import "gopkg.in/gemnasium/logrus-airbrake-hook.v2" + +import ( + "errors" + "fmt" + "net/http" + "os" + + "github.com/Sirupsen/logrus" + "gopkg.in/airbrake/gobrake.v2" +) + +// AirbrakeHook to send exceptions to an exception-tracking service compatible +// with the Airbrake API. +type airbrakeHook struct { + Airbrake *gobrake.Notifier +} + +func NewHook(projectID int64, apiKey, env string) *airbrakeHook { + airbrake := gobrake.NewNotifier(projectID, apiKey) + airbrake.AddFilter(func(notice *gobrake.Notice) *gobrake.Notice { + if env == "development" { + return nil + } + notice.Context["environment"] = env + return notice + }) + hook := &airbrakeHook{ + Airbrake: airbrake, + } + return hook +} + +func (hook *airbrakeHook) Fire(entry *logrus.Entry) error { + var notifyErr error + err, ok := entry.Data["error"].(error) + if ok { + notifyErr = err + } else { + notifyErr = errors.New(entry.Message) + } + var req *http.Request + for k, v := range entry.Data { + if r, ok := v.(*http.Request); ok { + req = r + delete(entry.Data, k) + break + } + } + notice := hook.Airbrake.Notice(notifyErr, req, 3) + for k, v := range entry.Data { + notice.Context[k] = fmt.Sprintf("%s", v) + } + + hook.sendNotice(notice) + return nil +} + +func (hook *airbrakeHook) sendNotice(notice *gobrake.Notice) { + if _, err := hook.Airbrake.SendNotice(notice); err != nil { + fmt.Fprintf(os.Stderr, "Failed to send error to Airbrake: %v\n", err) + } +} + +func (hook *airbrakeHook) Levels() []logrus.Level { + return []logrus.Level{ + logrus.ErrorLevel, + logrus.FatalLevel, + logrus.PanicLevel, + } +} |