From f1d0ea5b281ec529dc57638210ebf8528abac64a Mon Sep 17 00:00:00 2001 From: Joel Collins Date: Thu, 29 Oct 2020 14:06:15 +0000 Subject: [PATCH] Added API LogFileView --- openflexure_microscope/api/app.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/openflexure_microscope/api/app.py b/openflexure_microscope/api/app.py index ef97d475..2d2028d9 100644 --- a/openflexure_microscope/api/app.py +++ b/openflexure_microscope/api/app.py @@ -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/") def api_v1_catch_all(path): # pylint: disable=W0613