mattermost
mattermost copied to clipboard
Added download button for downloading logs from server logs page in system console.
Summary
Added download logs button in server logs page of admin in system console. When clicked logs get downloaded as mattermost.log file.
Ticket Link
Fixes https://github.com/mattermost/mattermost/issues/26320 Jira https://mattermost.atlassian.net/browse/MM-57013
Screenshots
before | after |
---|---|
before | after |
---|---|
Release Note
Added download functionality for admins to download server logs from Server Logs Page in System Console.
Hello @Aryakoste,
Thanks for your pull request! A Core Committer will review your pull request soon. For code contributions, you can learn more about the review process here.
E2E tests not automatically triggered, because the PR is not in a mergeable state. Please update the branch with the base branch and resolve outstanding conflicts.
@svelle Would you mind taking a look from an UX standpoint?
Creating a new SpinWick test server using Mattermost Cloud.
Enterprise Edition Image not available in the 30 minutes timeframe, checking the Team Edition Image and if available will use that.
Test server creation failed. Review the error details here.
Creating a new SpinWick test server using Mattermost Cloud.
Enterprise Edition Image not available in the 30 minutes timeframe, checking the Team Edition Image and if available will use that.
Should I make backend change as discussed or do the frontend changes given.
If you could do the backend change, that'd be great
Ok. Will make the backend change. So we have to use common endpoint of /logs/download for downloading both plain and JSON logs right ?.
Yeah, a new API for each of those would work. The body of the new methods will be mostly the same as the old ones except for the headers attached to the response to trigger the download. The API metrods can call web.WriteFileResponse
with true for its forceDownload
parameter to write all those headers for you.
Update:- I have made the api and checked the response. Just have to make some changes on frontend to make it properly work. Will commit my changes after that.
Test server creation failed. Review the error details here.
func downloadLogs(c *Context, w http.ResponseWriter, r *http.Request) {
lines, _ := c.App.GetLogs(c.AppContext, c.Params.Page, c.Params.LogsPerPage)
tmpfile, err := os.CreateTemp("", "logs-*.log")
if err != nil {
http.Error(w, "Failed to create temporary file", http.StatusInternalServerError)
return
}
defer tmpfile.Close()
defer os.Remove(tmpfile.Name())
for _, line := range lines {
if _, err := io.WriteString(tmpfile, line); err != nil {
http.Error(w, "Failed to write logs to file", http.StatusInternalServerError)
return
}
}
fileInfo, err := tmpfile.Stat()
if err != nil {
http.Error(w, "Failed to get file information", http.StatusInternalServerError)
return
}
web.WriteFileResponse("mattermost.log",
"text/plain",
fileInfo.Size(),
time.Now(),
*c.App.Config().ServiceSettings.WebserverMode,
tmpfile,
true,
w,
r)
}
this is the function/controller i wrote to download the log file. But the log file isnt downloading automatically. I have set the forceDownload parameter to true.
That's strange. I would've expected that to work, but perhaps something else is missing.
Could you push those changes so that I could try them out? They can either be part of this branch or on a separate one, but I want to be able to run the code locally
Test server creation failed. Review the error details here.
I have pushed the changes. Check and let me know.
Test server creation failed. Review the error details here.
Test server creation failed. Review the error details here.
Test server creation failed. Review the error details here.
Test server creation failed. Review the error details here.
@hanzei I'm not sure who your team usually assigns to QA test your tickets, so I assigned @yasserfaraazkhan. If there's someone else who'd be better to test it, feel free to re-assign
/update-branch
@Aryakoste can you check the CI failure ?
what does this check-i18n suggest me to do.
Looks like that that's complaining about the order of the translation strings being wrong. I can update that.
Edit: If you're ever needing to do it yourself, you can run npm run -w channels i18n-extract
to update that file
/update-branch
/e2e-tests
The command /e2e-test requires all PR checks to pass.