implement POST /logs for apiV4 (#6143)
Этот коммит содержится в:
коммит произвёл
George Goldberg
родитель
08822def53
Коммит
b57b5abce8
@@ -29,6 +29,7 @@ func InitSystem() {
|
||||
BaseRoutes.ApiRoot.Handle("/caches/invalidate", ApiSessionRequired(invalidateCaches)).Methods("POST")
|
||||
|
||||
BaseRoutes.ApiRoot.Handle("/logs", ApiSessionRequired(getLogs)).Methods("GET")
|
||||
BaseRoutes.ApiRoot.Handle("/logs", ApiSessionRequired(postLog)).Methods("POST")
|
||||
}
|
||||
|
||||
func getSystemPing(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -160,6 +161,34 @@ func getLogs(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte(model.ArrayToJson(lines)))
|
||||
}
|
||||
|
||||
func postLog(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !*utils.Cfg.ServiceSettings.EnableDeveloper && !app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
||||
m := model.MapFromJson(r.Body)
|
||||
lvl := m["level"]
|
||||
msg := m["message"]
|
||||
|
||||
if len(msg) > 400 {
|
||||
msg = msg[0:399]
|
||||
}
|
||||
|
||||
if lvl == "ERROR" {
|
||||
err := &model.AppError{}
|
||||
err.Message = msg
|
||||
err.Id = msg
|
||||
err.Where = "client"
|
||||
c.LogError(err)
|
||||
} else {
|
||||
l4g.Debug(msg)
|
||||
}
|
||||
|
||||
m["message"] = msg
|
||||
w.Write([]byte(model.MapToJson(m)))
|
||||
}
|
||||
|
||||
func getClientConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
format := r.URL.Query().Get("format")
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user