Added API LogFileView

This commit is contained in:
Joel Collins 2020-10-29 14:06:15 +00:00
parent 654f7229bd
commit f1d0ea5b28

View file

@ -23,7 +23,7 @@ from datetime import datetime
import pkg_resources
from flask import abort, send_file
from flask_cors import CORS, cross_origin
from labthings import create_app
from labthings import create_app, View
from labthings.extensions import find_extensions
from openflexure_microscope.api.microscope import default_microscope as api_microscope
@ -139,6 +139,19 @@ for name, action in views.enabled_root_actions().items():
rule = action["rule"]
labthing.add_view(view_class, f"/actions{rule}")
# Add log file view
class LogFileView(View):
def get(self):
"""
Most recent 1mb of log output
"""
timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
return send_file(
ROOT_LOGFILE,
as_attachment=True,
attachment_filename="openflexure_microscope_{}.log".format(timestamp),
)
labthing.add_view(LogFileView, "/log")
@app.route("/")
def openflexure_ev():
@ -153,20 +166,6 @@ def routes():
"""
return list_routes(app)
@app.route("/log")
def err_log():
"""
Most recent 1mb of log output
"""
timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
return send_file(
ROOT_LOGFILE,
as_attachment=True,
attachment_filename="openflexure_microscope_{}.log".format(timestamp),
)
@app.route("/api/v1/", defaults={"path": ""})
@app.route("/api/v1/<path:path>")
def api_v1_catch_all(path): # pylint: disable=W0613