diff --git a/.gitlab/issue_templates/Bug.md b/.gitlab/issue_templates/Bug.md index 000b3627..86300792 100644 --- a/.gitlab/issue_templates/Bug.md +++ b/.gitlab/issue_templates/Bug.md @@ -22,8 +22,8 @@ To access your microscope log, either: * Run `ofm log` on your microscope, and copy/paste the output here -* Go to `http://:5000/log`, download the log file, and attach it here using the "Attach a File" button below - * In most setups, `http://microscope.local:5000/log` should work +* Go to `http://:5000/logfile`, download the log file, and attach it here using the "Attach a File" button below + * In most setups, `http://microscope.local:5000/logfile` should work ## Additional details diff --git a/src/openflexure_microscope_server/logging.py b/src/openflexure_microscope_server/logging.py index 6afe04ef..9082e092 100644 --- a/src/openflexure_microscope_server/logging.py +++ b/src/openflexure_microscope_server/logging.py @@ -2,7 +2,7 @@ import logging from logging.handlers import RotatingFileHandler import os -from fastapi.responses import FileResponse, PlainTextResponse +from fastapi.responses import PlainTextResponse OFM_LOG_FOLDER = "/var/openflexure/logs/" OFM_LOG_FILE = os.path.join(OFM_LOG_FOLDER, "openflexure_microscope.log") @@ -50,6 +50,18 @@ def retrieve_log() -> PlainTextResponse: return PlainTextResponse(OFM_HANDLER.log_history) +def retrieve_log_from_file() -> PlainTextResponse: + """ + Returns the full log from the file for downloading. + + Note this is read and then sent as otherwise it causes a RuntimeError if it + is written to while sending through FileResponse + """ + with open(OFM_LOG_FILE, "r", encoding="utf-8") as logfile: + full_log = logfile.read() + return PlainTextResponse(full_log) + + class OFMHandler(logging.Handler): """ A child class of logging.Handler. This class handles storing the most recent diff --git a/src/openflexure_microscope_server/server/__init__.py b/src/openflexure_microscope_server/server/__init__.py index eff6fc48..7c938362 100644 --- a/src/openflexure_microscope_server/server/__init__.py +++ b/src/openflexure_microscope_server/server/__init__.py @@ -6,7 +6,7 @@ from labthings_fastapi.server import cli, ThingServer import uvicorn from .serve_static_files import add_static_files from .legacy_api import add_v2_endpoints -from ..logging import configure_logging, retrieve_log +from ..logging import configure_logging, retrieve_log, retrieve_log_from_file def customise_server(server: ThingServer): @@ -18,8 +18,9 @@ def customise_server(server: ThingServer): except RuntimeError: print("Failed to add static files - you will have to do without them!") - # Add an endpoint to get the log + # Add an endpoint to get the logs - (directly calling the FastAPI decorator) server.app.get("/log/")(retrieve_log) + server.app.get("/logfile/")(retrieve_log_from_file) def serve_from_cli(argv: Optional[list[str]] = None): diff --git a/webapp/src/components/tabContentComponents/loggingContent.vue b/webapp/src/components/tabContentComponents/loggingContent.vue index d74a27f5..2b7488c7 100644 --- a/webapp/src/components/tabContentComponents/loggingContent.vue +++ b/webapp/src/components/tabContentComponents/loggingContent.vue @@ -33,7 +33,7 @@ Download Log File @@ -128,9 +128,12 @@ export default { return items; }, - logFileURI: function() { + logURI: function() { return `${this.$store.getters.baseUri}/log/`; }, + logFileURI: function() { + return `${this.$store.getters.baseUri}/logfile/`; + }, pagedItems: function() { let startIndex = (this.page - 1) * this.maxitems; return this.filteredItems.slice(startIndex, startIndex + this.maxitems); @@ -153,7 +156,7 @@ export default { } }, async updateLogs() { - let response = await axios.get(this.logFileURI); + let response = await axios.get(this.logURI); let lines = response.data.split("\n"); let logs = []; let regexp = /\[(.+)\] \[(.+)\] (.*)$/;