Commit d8905600 authored by Lukas Matt's avatar Lukas Matt

Implement sentry logging if sentry.DSN is specified

* Added raven-go to Gopkg.lock

see https://docs.sentry.io/quickstart/#configure-the-dsn
parent 5cb69487
......@@ -58,6 +58,12 @@
revision = "adeb60566bc8c9202b0f1be7e3a675beedbc11f0"
version = "v1.13.2"
[[projects]]
name = "github.com/certifi/gocertifi"
packages = ["."]
revision = "deb3ae2ef2610fde3330947281941c562861188b"
version = "2018.01.18"
[[projects]]
branch = "master"
name = "github.com/dchest/captcha"
......@@ -92,6 +98,12 @@
packages = ["."]
revision = "9abcf5eec0dcc846a94586055522860d79550a70"
[[projects]]
branch = "master"
name = "github.com/getsentry/raven-go"
packages = ["."]
revision = "7562301a6763c9ac631b0a2011b4aa0e064e45d4"
[[projects]]
name = "github.com/go-ini/ini"
packages = ["."]
......@@ -192,6 +204,12 @@
packages = ["."]
revision = "9520e82c474b0a04dd04f8a40959027271bab992"
[[projects]]
name = "github.com/pkg/errors"
packages = ["."]
revision = "645ef00459ed84a119197bfb8d8205042c6df63d"
version = "v0.8.0"
[[projects]]
name = "github.com/revel/cmd"
packages = [
......@@ -331,6 +349,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "e5165afc0ebe22ad8ab93707ffc02b66dd0955221d591d904bad606a724cb0bf"
inputs-digest = "14b643ec3911f1cb78773075d5a0a8f051e4e415b2629d5fa1a8d0ccea86efb5"
solver-name = "gps-cdcl"
solver-version = 1
......@@ -21,12 +21,34 @@ import (
"fmt"
"github.com/revel/revel"
federation "github.com/ganggo/federation"
"github.com/revel/log15"
"github.com/getsentry/raven-go"
)
type AppLogWrapper struct {
Name string
}
// SentryLogHandler will intercept logging and send all errors
// with a log level greater then info to the specified DSN
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)
}
// search for errors and send them
// asynchronously to the sentry endpoint
for _, ctx := range record.Ctx {
if err, ok := ctx.(error); ok {
raven.CaptureError(err, nil)
}
}
return revel.GetRootLogHandler().Log(record)
}
func (wrap AppLogWrapper) Println(v ...interface{}) { wrap.Print(v) }
func (wrap AppLogWrapper) Print(v ...interface{}) {
......
......@@ -31,6 +31,7 @@ import (
"strings"
"fmt"
"time"
"github.com/getsentry/raven-go"
)
// will be set on compile time
......@@ -106,11 +107,19 @@ func init() {
revel.OnAppStart(InitDB)
revel.OnAppStart(InitSocialRelay)
// set federation logger to revel
// set custom logger options
revel.OnAppStart(func() {
federation.SetLogger(helpers.AppLogWrapper{
Name: "federation",
})
// if sentry credentials exists
// send reports to upstream
revel.Config.SetSection("ganggo")
sentryDSN, found := revel.Config.String("sentry.DSN")
if found {
raven.SetDSN(sentryDSN)
revel.RootLog.SetHandler(helpers.SentryLogHandler{})
}
})
// register jobs running on an interval
......
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