Commit 7d17c8d0 authored by zauberstuhl's avatar zauberstuhl

Merge branch 'sentry_logging' into 'master'

Sentry logging

Closes #69

See merge request !73
parents 51fc947a 33c9c6d2
Pipeline #512 canceled with stages
......@@ -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)
}
}
......
......@@ -84,7 +84,7 @@ func (receiver *Receiver) CheckAuthor(author string) (models.Person, bool) {
// if he doesn't exist locally
fetch := FetchAuthor{Author: author}; fetch.Run()
if fetch.Err != nil {
revel.AppLog.Error("Cannot fetch author", "error", fetch.Err)
revel.AppLog.Debug("Cannot fetch author", "error", fetch.Err)
}
return fetch.Person, fetch.Err == nil
}
......@@ -87,16 +87,16 @@ func (c *Contact) Update() error {
}
defer db.Close()
var dbContact Contact
sharing := c.Sharing
if c.ID <= 0 {
err = db.Where("user_id = ? AND person_id = ?",
c.UserID, c.PersonID).First(&dbContact).Error
c.UserID, c.PersonID).First(c).Error
if err != nil {
return err
}
}
return db.Model(&dbContact).Update("sharing", c.Sharing).Error
return db.Model(c).Update("sharing", sharing).Error
}
func (c *Contacts) FindByUserID(id uint) error {
......
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