error logging with schiavo -> error logging with sentry
This commit is contained in:
parent
24d34eb741
commit
06eb64ecf5
|
@ -1,27 +0,0 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.zxq.co/ripple/schiavolib"
|
||||
"github.com/fatih/color"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// ErrorHandler is a middleware for gin that takes care of calls to c.Error().
|
||||
func ErrorHandler() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
c.Next()
|
||||
errs := c.Errors.Errors()
|
||||
if len(errs) != 0 {
|
||||
color.Red("!!! ERRORS OCCURRED !!!")
|
||||
var out string
|
||||
out += fmt.Sprintf("==> %s %s\n", c.Request.Method, c.Request.URL.Path)
|
||||
for _, err := range errs {
|
||||
out += fmt.Sprintf("===> %s\n", err)
|
||||
}
|
||||
color.Red(out)
|
||||
go schiavo.Bunker.Send("Errors occurred:\n```\n" + out + "```")
|
||||
}
|
||||
}
|
||||
}
|
17
app/start.go
17
app/start.go
|
@ -2,12 +2,15 @@ package app
|
|||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"git.zxq.co/ripple/rippleapi/app/internals"
|
||||
"git.zxq.co/ripple/rippleapi/app/peppy"
|
||||
"git.zxq.co/ripple/rippleapi/app/v1"
|
||||
"git.zxq.co/ripple/rippleapi/common"
|
||||
"github.com/getsentry/raven-go"
|
||||
"github.com/gin-gonic/contrib/gzip"
|
||||
"github.com/gin-gonic/contrib/sentry"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
|
@ -17,7 +20,16 @@ var db *sql.DB
|
|||
func Start(conf common.Conf, dbO *sql.DB) *gin.Engine {
|
||||
db = dbO
|
||||
r := gin.Default()
|
||||
r.Use(gzip.Gzip(gzip.DefaultCompression), ErrorHandler())
|
||||
r.Use(gzip.Gzip(gzip.DefaultCompression))
|
||||
|
||||
if conf.SentryDSN != "" {
|
||||
ravenClient, err := raven.New(conf.SentryDSN)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
r.Use(sentry.Recovery(ravenClient, false))
|
||||
}
|
||||
}
|
||||
|
||||
api := r.Group("/api")
|
||||
{
|
||||
|
@ -80,6 +92,9 @@ func Start(conf common.Conf, dbO *sql.DB) *gin.Engine {
|
|||
}
|
||||
|
||||
api.GET("/status", internals.Status)
|
||||
api.GET("/errore_meme", func(c *gin.Context) {
|
||||
c.Error(fmt.Errorf("This is a test error!"))
|
||||
})
|
||||
|
||||
// peppyapi
|
||||
api.GET("/get_user", PeppyMethod(peppy.GetUser))
|
||||
|
|
|
@ -13,6 +13,7 @@ type Conf struct {
|
|||
DSN string `description:"The Data Source Name for the database. More: https://github.com/go-sql-driver/mysql#dsn-data-source-name"`
|
||||
ListenTo string `description:"The IP/Port combination from which to take connections, e.g. :8080"`
|
||||
Unix bool `description:"Bool indicating whether ListenTo is a UNIX socket or an address."`
|
||||
SentryDSN string `description:"thing for sentry whatever"`
|
||||
}
|
||||
|
||||
var cachedConf *Conf
|
||||
|
|
Loading…
Reference in New Issue
Block a user