Commit bda9fac5 authored by zauberstuhl's avatar zauberstuhl
Browse files

Improve sentry logger

parent ec7a8d8b
Pipeline #507 passed with stages
in 7 minutes and 21 seconds
......@@ -23,6 +23,7 @@ import (
federation "git.feneas.org/ganggo/federation"
"github.com/revel/log15"
"github.com/getsentry/raven-go"
"errors"
)
type AppLogWrapper struct {
......@@ -34,15 +35,29 @@ type AppLogWrapper struct {
type SentryLogHandler struct {}
func (handler SentryLogHandler) Log(record *log15.Record) error {
// if log level is info or debug return and do nothing
if record.Lvl == log15.LvlInfo || record.Lvl == log15.LvlDebug {
return revel.GetRootLogHandler().Log(record)
}
if record.Lvl == log15.LvlError || record.Lvl == log15.LvlCrit {
var errs []error
// search for errors in the logger context
for _, ctx := range record.Ctx {
if err, ok := ctx.(error); ok {
errs = append(errs, err)
}
}
if len(errs) == 0 {
// there was an error/crit event but no error type
// was found lets create one and send it to sentry
var errMsg string
for _, ctx := range record.Ctx {
if msg, ok := ctx.(string); ok {
errMsg = errMsg + " " + msg
}
}
errs = append(errs, errors.New(errMsg))
}
// search for errors and send them
// asynchronously to the sentry endpoint
for _, ctx := range record.Ctx {
if err, ok := ctx.(error); ok {
// send asynchronously to the sentry endpoint
for _, err := range errs {
raven.CaptureError(err, nil)
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment