mirror of
https://github.com/grafana/grafana.git
synced 2024-11-28 03:34:15 -06:00
a8eef45a44
* migrate log15 to gokit/log * fix console log * update some unittest * fix all unittest * fix the build * Update pkg/infra/log/log.go Co-authored-by: Yuriy Tseretyan <tceretian@gmail.com> * general type vector * correct the level key Co-authored-by: Yuriy Tseretyan <tceretian@gmail.com>
49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/getsentry/sentry-go"
|
|
"github.com/grafana/grafana/pkg/api/frontendlogging"
|
|
"github.com/grafana/grafana/pkg/api/response"
|
|
"github.com/grafana/grafana/pkg/infra/log"
|
|
"github.com/grafana/grafana/pkg/models"
|
|
"github.com/grafana/grafana/pkg/web"
|
|
)
|
|
|
|
var frontendLogger = log.New("frontend")
|
|
|
|
type frontendLogMessageHandler func(c *models.ReqContext) response.Response
|
|
|
|
func NewFrontendLogMessageHandler(store *frontendlogging.SourceMapStore) frontendLogMessageHandler {
|
|
return func(c *models.ReqContext) response.Response {
|
|
event := frontendlogging.FrontendSentryEvent{}
|
|
if err := web.Bind(c.Req, &event); err != nil {
|
|
return response.Error(http.StatusBadRequest, "bad request data", err)
|
|
}
|
|
|
|
var msg = "unknown"
|
|
|
|
if len(event.Message) > 0 {
|
|
msg = event.Message
|
|
} else if event.Exception != nil && len(event.Exception.Values) > 0 {
|
|
msg = event.Exception.Values[0].FmtMessage()
|
|
}
|
|
|
|
var ctx = event.ToLogContext(store)
|
|
|
|
switch event.Level {
|
|
case sentry.LevelError:
|
|
frontendLogger.Error(msg, ctx...)
|
|
case sentry.LevelWarning:
|
|
frontendLogger.Warn(msg, ctx...)
|
|
case sentry.LevelDebug:
|
|
frontendLogger.Debug(msg, ctx...)
|
|
default:
|
|
frontendLogger.Info(msg, ctx...)
|
|
}
|
|
|
|
return response.Success("ok")
|
|
}
|
|
}
|