tidy up logging

This commit is contained in:
Damien Elmes 2020-07-07 10:50:12 +10:00
parent 4ab9d04c95
commit 85cbd263da

View File

@ -14,6 +14,7 @@ from http import HTTPStatus
import flask import flask
import flask_cors # type: ignore import flask_cors # type: ignore
import time
from flask import request from flask import request
from waitress.server import create_server from waitress.server import create_server
@ -56,7 +57,6 @@ class MediaServer(threading.Thread):
if devMode: if devMode:
# idempotent if logging has already been set up # idempotent if logging has already been set up
logging.basicConfig() logging.basicConfig()
else:
logging.getLogger("waitress").setLevel(logging.ERROR) logging.getLogger("waitress").setLevel(logging.ERROR)
desired_port = int(os.getenv("ANKI_API_PORT", "0")) desired_port = int(os.getenv("ANKI_API_PORT", "0"))
@ -124,7 +124,7 @@ def allroutes(pathin):
) )
if devMode: if devMode:
print("Sending file '%s - %s'" % (directory, path)) print(f"{time.time():.3f} {flask.request.method} /{pathin}")
try: try:
if flask.request.method == "POST": if flask.request.method == "POST":
@ -149,7 +149,14 @@ def allroutes(pathin):
else: else:
# autodetect # autodetect
mimetype = None mimetype = None
if os.path.exists(fullpath):
return flask.send_file(fullpath, mimetype=mimetype, conditional=True) return flask.send_file(fullpath, mimetype=mimetype, conditional=True)
else:
print(f"Not found: {pathin}")
return flask.make_response(
f"Invalid path: {pathin}",
HTTPStatus.NOT_FOUND,
)
except Exception as error: except Exception as error:
if devMode: if devMode: