Merge pull request #866 from mattermost/PLT-345

PLT-345 adding client side logging
Этот коммит содержится в:
Christopher Speller
2015-10-01 07:26:54 -04:00
родитель 53bdc34f37 0da42c5559
Коммит 9ce826863b
3 изменённых файлов: 56 добавлений и 1 удалений

Просмотреть файл

@@ -23,8 +23,10 @@ func InitAdmin(r *mux.Router) {
sr.Handle("/logs", ApiUserRequired(getLogs)).Methods("GET")
sr.Handle("/config", ApiUserRequired(getConfig)).Methods("GET")
sr.Handle("/save_config", ApiUserRequired(saveConfig)).Methods("POST")
sr.Handle("/client_props", ApiAppHandler(getClientProperties)).Methods("GET")
sr.Handle("/test_email", ApiUserRequired(testEmail)).Methods("POST")
sr.Handle("/client_props", ApiAppHandler(getClientProperties)).Methods("GET")
sr.Handle("/log_client", ApiAppHandler(logClient)).Methods("POST")
}
func getLogs(c *Context, w http.ResponseWriter, r *http.Request) {
@@ -59,6 +61,26 @@ func getClientProperties(c *Context, w http.ResponseWriter, r *http.Request) {
w.Write([]byte(model.MapToJson(utils.ClientProperties)))
}
func logClient(c *Context, w http.ResponseWriter, r *http.Request) {
m := model.MapFromJson(r.Body)
lvl := m["level"]
msg := m["message"]
if len(msg) > 400 {
msg = msg[0:399]
}
if lvl == "ERROR" {
err := model.NewAppError("client", msg, "")
c.LogError(err)
}
rm := make(map[string]string)
rm["SUCCESS"] = "true"
w.Write([]byte(model.MapToJson(rm)))
}
func getConfig(c *Context, w http.ResponseWriter, r *http.Request) {
if !c.HasSystemAdminPermissions("getConfig") {
return