MM-57013 Added download button for downloading logs from server logs page in system console (#26389)
* added download system logs * download all logs * download all logs check-lint fix * check lint fix * download logs api * download logs api working * download logs working with error log * linting issues and code cleanup * CI check fix * documented the api and logs from file with error handling * test and final changes done * final changes done * Fix order of server-side translations * Fix incorrect indentation of logs.yaml --------- Co-authored-by: Harrison Healey <harrisonmhealey@gmail.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
71c25fb316
Коммит
a8b18ac807
@@ -50,6 +50,7 @@ func (api *API) InitSystem() {
|
||||
api.BaseRoutes.APIRoot.Handle("/caches/invalidate", api.APISessionRequired(invalidateCaches)).Methods("POST")
|
||||
|
||||
api.BaseRoutes.APIRoot.Handle("/logs", api.APISessionRequired(getLogs)).Methods("GET")
|
||||
api.BaseRoutes.APIRoot.Handle("/logs/download", api.APISessionRequired(downloadLogs)).Methods("GET")
|
||||
api.BaseRoutes.APIRoot.Handle("/logs/query", api.APISessionRequired(queryLogs)).Methods("POST")
|
||||
api.BaseRoutes.APIRoot.Handle("/logs", api.APIHandler(postLog)).Methods("POST")
|
||||
|
||||
@@ -414,6 +415,36 @@ func getLogs(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte(model.ArrayToJSON(lines)))
|
||||
}
|
||||
|
||||
func downloadLogs(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
auditRec := c.MakeAuditRecord("downloadLogs", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
if *c.App.Config().ExperimentalSettings.RestrictSystemAdmin {
|
||||
c.Err = model.NewAppError("downloadLogs", "api.restricted_system_admin", nil, "", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
if !c.App.SessionHasPermissionTo(*c.AppContext.Session(), model.PermissionGetLogs) {
|
||||
c.SetPermissionError(model.PermissionGetLogs)
|
||||
return
|
||||
}
|
||||
|
||||
fileData, err := c.App.GetMattermostLog(c.AppContext)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("downloadLogs", "api.system.logs.download_bytes_buffer.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
reader := bytes.NewReader(fileData.Body)
|
||||
web.WriteFileResponse("mattermost.log",
|
||||
"text/plain",
|
||||
int64(len(fileData.Body)),
|
||||
time.Now(),
|
||||
*c.App.Config().ServiceSettings.WebserverMode,
|
||||
reader,
|
||||
true,
|
||||
w,
|
||||
r)
|
||||
}
|
||||
|
||||
func postLog(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
forceToDebug := false
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user